Skip to content

Commit

Permalink
#982 fix formatting of python script
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Jun 27, 2016
1 parent 774698e commit 73f3ef4
Showing 1 changed file with 47 additions and 32 deletions.
79 changes: 47 additions & 32 deletions framework/pym/play/commands/modulesrepo.py
Expand Up @@ -72,6 +72,7 @@ def get_repositories(play_base):
return repos
return [DEFAULT_REPO]


class Downloader(object):
before = .0
history = []
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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')
Expand Down Expand Up @@ -443,6 +455,7 @@ def install(app, args, env):
print '~'
sys.exit(0)


def add(app, args, env):
app.check()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73f3ef4

Please sign in to comment.