Skip to content

Instantly share code, notes, and snippets.

@oldrev
Last active August 29, 2015 14:03
Show Gist options
  • Save oldrev/8e678680adf2ced6bad9 to your computer and use it in GitHub Desktop.
Save oldrev/8e678680adf2ced6bad9 to your computer and use it in GitHub Desktop.
#encoding: utf-8
# Orchard Language Package Cleanner
# Author: Wei "oldrev" Li <liwei@sandwych.com>
# 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 != LOCAL]
for d in dirs:
print 'Deleting: ', 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('App_Data\\Localization\\' + LOCAL):
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 ' + LOCAL
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment