From 73f3ef42153d35ef7ae660d0a0215bea504bf3f3 Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Mon, 27 Jun 2016 02:13:06 +0300 Subject: [PATCH] #982 fix formatting of python script --- framework/pym/play/commands/modulesrepo.py | 79 +++++++++++++--------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/framework/pym/play/commands/modulesrepo.py b/framework/pym/play/commands/modulesrepo.py index e0690fd452..26c923c699 100644 --- a/framework/pym/play/commands/modulesrepo.py +++ b/framework/pym/play/commands/modulesrepo.py @@ -72,6 +72,7 @@ def get_repositories(play_base): return repos return [DEFAULT_REPO] + class Downloader(object): before = .0 history = [] @@ -128,6 +129,7 @@ def bar(self, done): result = ('%d%%' % (done,)).center(self.width) return result.replace(' ', '-', int(span - offset)) + class Unzip: def __init__(self, verbose = False, percent = 10): self.verbose = verbose @@ -151,9 +153,11 @@ def extract(self, file, dir): complete = int (i / perc) * percent if not name.endswith('/'): outfile = open(os.path.join(dir, name), 'wb') - outfile.write(zf.read(name)) - outfile.flush() - outfile.close() + try: + outfile.write(zf.read(name)) + outfile.flush() + finally: + outfile.close() def _createstructure(self, file, dir): self._makedirs(self._listdirs(file), dir) @@ -177,6 +181,7 @@ def _listdirs(self, file): dirs.sort() return dirs + def new(app, args, play_env): if os.path.exists(app.path): print "~ Oops. %s already exists" % app.path @@ -213,6 +218,7 @@ def new(app, args, play_env): print "~ Have fun!" print "~" + def list(app, args): print "~ You can also browse this list online at:" for repo in repositories: @@ -272,21 +278,23 @@ def build(app, args, env): deps_file = os.path.join(app.path, 'conf', 'dependencies.yml') if os.path.exists(deps_file): f = open(deps_file) - deps = yaml.load(f.read()) - if 'self' in deps: - splitted = deps["self"].split(" -> ") - if len(splitted) == 2: - nameAndVersion = splitted.pop().strip() - splitted = nameAndVersion.split(" ") - if len(splitted) == 2: - version = splitted.pop() - name = splitted.pop() - for dep in deps["require"]: - if isinstance(dep, basestring): - splitted = dep.split(" ") - if len(splitted) == 2 and splitted[0] == "play": - fwkMatch = splitted[1] - f.close + try: + deps = yaml.load(f.read()) + if 'self' in deps: + splitted = deps["self"].split(" -> ") + if len(splitted) == 2: + nameAndVersion = splitted.pop().strip() + splitted = nameAndVersion.split(" ") + if len(splitted) == 2: + version = splitted.pop() + name = splitted.pop() + for dep in deps["require"]: + if isinstance(dep, basestring): + splitted = dep.split(" ") + if len(splitted) == 2 and splitted[0] == "play": + fwkMatch = splitted[1] + finally: + f.close() if name is None: name = os.path.basename(app.path) @@ -298,7 +306,7 @@ def build(app, args, env): if os.path.exists(deps_file): f = open(deps_file) deps = yaml.load(f.read()) - if 'self' in deps: + if 'self' in deps: splitted = deps["self"].split(" -> ") f.close() if len(splitted) == 2: @@ -312,7 +320,6 @@ def build(app, args, env): replaceAll(deps_file, origModuleDefinition, modifiedModuleDefinition) except: pass - build_file = os.path.join(app.path, 'build.xml') if os.path.exists(build_file): @@ -334,20 +341,24 @@ def build(app, args, env): manifest = os.path.join(app.path, 'manifest') manifestF = open(manifest, 'w') - manifestF.write('version=%s\nframeworkVersions=%s\n' % (version, fwkMatch)) - manifestF.close() + try: + manifestF.write('version=%s\nframeworkVersions=%s\n' % (version, fwkMatch)) + finally: + manifestF.close() zip = zipfile.ZipFile(os.path.join(dist_dir, '%s.zip' % mv), 'w', zipfile.ZIP_STORED) - for (dirpath, dirnames, filenames) in os.walk(app.path): - if dirpath == dist_dir: - continue - if dirpath.find(os.sep + '.') > -1 or dirpath.find('/tmp/') > -1 or dirpath.find('/test-result/') > -1 or dirpath.find('/logs/') > -1 or dirpath.find('/eclipse/') > -1 or dirpath.endswith('/test-result') or dirpath.endswith('/logs') or dirpath.endswith('/eclipse') or dirpath.endswith('/nbproject'): - continue - for file in filenames: - if file.find('~') > -1 or file.endswith('.iml') or file.startswith('.'): + try: + for (dirpath, dirnames, filenames) in os.walk(app.path): + if dirpath == dist_dir: + continue + if dirpath.find(os.sep + '.') > -1 or dirpath.find('/tmp/') > -1 or dirpath.find('/test-result/') > -1 or dirpath.find('/logs/') > -1 or dirpath.find('/eclipse/') > -1 or dirpath.endswith('/test-result') or dirpath.endswith('/logs') or dirpath.endswith('/eclipse') or dirpath.endswith('/nbproject'): continue - zip.write(os.path.join(dirpath, file), os.path.join(dirpath[len(app.path):], file)) - zip.close() + for file in filenames: + if file.find('~') > -1 or file.endswith('.iml') or file.startswith('.'): + continue + zip.write(os.path.join(dirpath, file), os.path.join(dirpath[len(app.path):], file)) + finally: + zip.close() os.remove(manifest) @@ -363,6 +374,7 @@ def build(app, args, env): print "~ Package is available at %s" % os.path.join(dist_dir, '%s.zip' % mv) print "~" + def install(app, args, env): if len(sys.argv) < 3: help_file = os.path.join(env["basedir"], 'documentation/commands/cmd-install.txt') @@ -443,6 +455,7 @@ def install(app, args, env): print '~' sys.exit(0) + def add(app, args, env): app.check() @@ -481,7 +494,8 @@ def add(app, args, env): print "~ Module %s add to application %s." % (mn, app.name()) print "~ " -def load_module_list(custom_server): + +def load_module_list(custom_server=None): def addServer(module, server): module['server'] = server @@ -509,6 +523,7 @@ def any(arr, func): modules.append(addServer(module, repo)) return modules + def load_modules_from(modules_server): try: url = '%s/modules' % modules_server