Skip to content

Instantly share code, notes, and snippets.

@ccdos
Forked from oldrev/orchard_clear.py
Created June 28, 2014 12:30
Show Gist options
  • Select an option

  • Save ccdos/fe2b0014b81a8ba60e9c to your computer and use it in GitHub Desktop.

Select an option

Save ccdos/fe2b0014b81a8ba60e9c to your computer and use it in GitHub Desktop.

Revisions

  1. @oldrev oldrev revised this gist Jun 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion orchard_clear.py
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    def purge(dir):
    dirs = [os.path.join(dir, o) for o in os.listdir(dir) if os.path.isdir(os.path.join(dir, o)) and o != LOCAL]
    for d in dirs:
    print 'Delete directory: ', d
    print 'Deleting: ', d
    shutil.rmtree(d)

    def purge_all(dir):
  2. @oldrev oldrev revised this gist Jun 28, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions orchard_clear.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    #encoding: utf-8

    # Orchard Language Package Cleanner for zh-CN
    # Orchard Language Package Cleanner
    # Author: Wei "oldrev" Li <[email protected]>
    # License: New BSD

    import sys, os, shutil

    LOCAL = 'zh-CN'

    def purge(dir):
    dirs = [os.path.join(dir, o) for o in os.listdir(dir) if os.path.isdir(os.path.join(dir, o)) and o != 'zh-CN']
    dirs = [os.path.join(dir, o) for o in os.listdir(dir) if os.path.isdir(os.path.join(dir, o)) and o != LOCAL]
    for d in dirs:
    print 'Delete directory: ', d
    shutil.rmtree(d)
    @@ -16,7 +18,7 @@ def purge_all(dir):
    for root, dirs, files in os.walk(dir):
    for f in files:
    fp = os.path.join(root, f)
    if root.endswith(r'App_Data\Localization\zh-CN'):
    if root.endswith('App_Data\\Localization\\' + LOCAL):
    dp = os.path.dirname(root)
    purge(dp)

    @@ -36,7 +38,7 @@ def print_usage():
    print 'python {0} <path-to-orchard-language-package>'.format(sys.argv[0])
    print

    print 'Orchard CMS Language Package Cleanner for zh-CN'
    print 'Orchard CMS Language Package Cleanner for ' + LOCAL

    if len(sys.argv) < 2:
    print_usage()
  3. @oldrev oldrev created this gist Jun 28, 2014.
    50 changes: 50 additions & 0 deletions orchard_clear.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #encoding: utf-8

    # Orchard Language Package Cleanner for zh-CN
    # Author: Wei "oldrev" Li <[email protected]>
    # License: New BSD

    import sys, os, shutil

    def purge(dir):
    dirs = [os.path.join(dir, o) for o in os.listdir(dir) if os.path.isdir(os.path.join(dir, o)) and o != 'zh-CN']
    for d in dirs:
    print 'Delete directory: ', d
    shutil.rmtree(d)

    def purge_all(dir):
    for root, dirs, files in os.walk(dir):
    for f in files:
    fp = os.path.join(root, f)
    if root.endswith(r'App_Data\Localization\zh-CN'):
    dp = os.path.dirname(root)
    purge(dp)

    def check_orchard_directory(root):
    subdirs = ['Core', 'App_Data', 'Themes', 'Modules']
    if not os.path.isdir(root):
    return False
    for subdir in subdirs:
    dir = os.path.join(root, subdir)
    if not os.path.isdir(dir):
    return False
    return True

    def print_usage():
    print
    print 'Usage: '
    print 'python {0} <path-to-orchard-language-package>'.format(sys.argv[0])
    print

    print 'Orchard CMS Language Package Cleanner for zh-CN'

    if len(sys.argv) < 2:
    print_usage()
    exit()

    if not check_orchard_directory(sys.argv[1]):
    print 'Error: The path "{0}" seems not like an Orchard language package.'.format(sys.argv[1])
    exit()

    print "Cleaning po files..."
    purge_all(sys.argv[1])