Make commands invocation generic.
This commit is contained in:
parent
b40f4f7d91
commit
f041088ab7
@ -15,13 +15,13 @@
|
|||||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
# Boston, MA 02111-1307, USA.
|
# Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import gettext
|
import gettext
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
from sugar import env
|
from sugar import env
|
||||||
from sugar.bundle.activitybundle import ActivityBundle
|
from sugar.bundle.activitybundle import ActivityBundle
|
||||||
@ -121,7 +121,7 @@ def _get_bundle_id():
|
|||||||
bundle = ActivityBundle(_get_source_path())
|
bundle = ActivityBundle(_get_source_path())
|
||||||
return bundle.get_bundle_id()
|
return bundle.get_bundle_id()
|
||||||
|
|
||||||
def cmd_help():
|
def cmd_help(config, options, args):
|
||||||
print 'Usage: \n\
|
print 'Usage: \n\
|
||||||
setup.py dev - setup for development \n\
|
setup.py dev - setup for development \n\
|
||||||
setup.py dist - create a bundle package \n\
|
setup.py dist - create a bundle package \n\
|
||||||
@ -134,7 +134,7 @@ setup.py release - do a new release of the bundle \n\
|
|||||||
setup.py help - print this message \n\
|
setup.py help - print this message \n\
|
||||||
'
|
'
|
||||||
|
|
||||||
def cmd_dev():
|
def cmd_dev(config, options, args):
|
||||||
bundle_path = env.get_user_activities_path()
|
bundle_path = env.get_user_activities_path()
|
||||||
if not os.path.isdir(bundle_path):
|
if not os.path.isdir(bundle_path):
|
||||||
os.mkdir(bundle_path)
|
os.mkdir(bundle_path)
|
||||||
@ -186,8 +186,9 @@ def _get_activity_name():
|
|||||||
match = re.search('^name\s*=\s*(.*)$', info, flags = re.MULTILINE)
|
match = re.search('^name\s*=\s*(.*)$', info, flags = re.MULTILINE)
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
def cmd_dist(config):
|
def cmd_dist(config, options, args):
|
||||||
cmd_genl10n(config.bundle_name, config.manifest)
|
cmd_genl10n(config, options, args)
|
||||||
|
|
||||||
file_list = _get_file_list(config.manifest)
|
file_list = _get_file_list(config.manifest)
|
||||||
|
|
||||||
zipname = _get_package_name(config.bundle_name)
|
zipname = _get_package_name(config.bundle_name)
|
||||||
@ -202,18 +203,20 @@ def cmd_dist(config):
|
|||||||
|
|
||||||
bundle_zip.close()
|
bundle_zip.close()
|
||||||
|
|
||||||
def cmd_install(config, path):
|
def cmd_install(config, options, args):
|
||||||
cmd_dist(config)
|
path = args[0]
|
||||||
cmd_uninstall(path)
|
|
||||||
|
cmd_dist(config, options, args)
|
||||||
|
cmd_uninstall(config, options, args)
|
||||||
|
|
||||||
_extract_bundle(_get_package_name(config.bundle_name), path)
|
_extract_bundle(_get_package_name(config.bundle_name), path)
|
||||||
|
|
||||||
def cmd_uninstall(config, path):
|
def cmd_uninstall(config, options, args):
|
||||||
path = os.path.join(path, _get_bundle_dir())
|
path = os.path.join(args[0], _get_bundle_dir())
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def cmd_genpot(config):
|
def cmd_genpot(config, options, args):
|
||||||
po_path = os.path.join(_get_source_path(), 'po')
|
po_path = os.path.join(_get_source_path(), 'po')
|
||||||
if not os.path.isdir(po_path):
|
if not os.path.isdir(po_path):
|
||||||
os.mkdir(po_path)
|
os.mkdir(po_path)
|
||||||
@ -247,7 +250,7 @@ def cmd_genpot(config):
|
|||||||
print 'ERROR - xgettext failed with return code %i.' % retcode
|
print 'ERROR - xgettext failed with return code %i.' % retcode
|
||||||
|
|
||||||
|
|
||||||
def cmd_genl10n(config):
|
def cmd_genl10n(config, options, args):
|
||||||
source_path = _get_source_path()
|
source_path = _get_source_path()
|
||||||
activity_name = _get_activity_name()
|
activity_name = _get_activity_name()
|
||||||
|
|
||||||
@ -273,7 +276,7 @@ def cmd_genl10n(config):
|
|||||||
f.write('[Activity]\nname = %s\n' % translated_name)
|
f.write('[Activity]\nname = %s\n' % translated_name)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def cmd_release(config):
|
def cmd_release(config, options, args):
|
||||||
if not os.path.isdir('.git'):
|
if not os.path.isdir('.git'):
|
||||||
print 'ERROR - this command works only for git repositories'
|
print 'ERROR - this command works only for git repositories'
|
||||||
|
|
||||||
@ -350,11 +353,11 @@ def cmd_release(config):
|
|||||||
print 'ERROR - cannot push to git'
|
print 'ERROR - cannot push to git'
|
||||||
|
|
||||||
print 'Creating the bundle...'
|
print 'Creating the bundle...'
|
||||||
cmd_dist(config)
|
cmd_dist(config, options, args)
|
||||||
|
|
||||||
print 'Done.'
|
print 'Done.'
|
||||||
|
|
||||||
def cmd_clean(config):
|
def cmd_clean(config, options, args):
|
||||||
os.path.walk('.', _delete_backups, None)
|
os.path.walk('.', _delete_backups, None)
|
||||||
|
|
||||||
def sanity_check():
|
def sanity_check():
|
||||||
@ -364,30 +367,15 @@ def sanity_check():
|
|||||||
def start(bundle_name, manifest='MANIFEST'):
|
def start(bundle_name, manifest='MANIFEST'):
|
||||||
sanity_check()
|
sanity_check()
|
||||||
|
|
||||||
|
parser = OptionParser()
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
config = Config(bundle_name, manifest)
|
config = Config(bundle_name, manifest)
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
try:
|
||||||
cmd_help(config)
|
globals()['cmd_' + args[0]](config, options, args[1:])
|
||||||
elif sys.argv[1] == 'build':
|
except (KeyError, IndexError):
|
||||||
pass
|
cmd_help(config, options, args)
|
||||||
elif sys.argv[1] == 'dev':
|
|
||||||
cmd_dev(config)
|
|
||||||
elif sys.argv[1] == 'dist':
|
|
||||||
cmd_dist(config)
|
|
||||||
elif sys.argv[1] == 'install' and len(sys.argv) == 3:
|
|
||||||
cmd_install(config, sys.argv[2])
|
|
||||||
elif sys.argv[1] == 'uninstall' and len(sys.argv) == 3:
|
|
||||||
cmd_uninstall(config, sys.argv[2])
|
|
||||||
elif sys.argv[1] == 'genpot':
|
|
||||||
cmd_genpot(config)
|
|
||||||
elif sys.argv[1] == 'genl10n':
|
|
||||||
cmd_genl10n(config)
|
|
||||||
elif sys.argv[1] == 'clean':
|
|
||||||
cmd_clean(config)
|
|
||||||
elif sys.argv[1] == 'release':
|
|
||||||
cmd_release(config)
|
|
||||||
else:
|
|
||||||
cmd_help(config)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
start()
|
start()
|
||||||
|
Loading…
Reference in New Issue
Block a user