Last active
August 29, 2015 14:03
-
-
Save oldrev/8e678680adf2ced6bad9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 'Usage: ' | |
print 'python {0} <path-to-orchard-language-package>'.format(sys.argv[0]) | |
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