mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
More PEP8 compliance (build.py, partial)
This commit is contained in:
parent
bd34fc2530
commit
2f6ce712f5
1 changed files with 61 additions and 44 deletions
|
|
@ -31,14 +31,17 @@ from ConfigParser import ConfigParser
|
|||
from optparse import OptionParser, OptionError
|
||||
import logging
|
||||
|
||||
import common, metadata
|
||||
import common
|
||||
import metadata
|
||||
from common import BuildException, VCSException, FDroidPopen, SilentPopen
|
||||
|
||||
|
||||
def get_builder_vm_id():
|
||||
vd = os.path.join('builder', '.vagrant')
|
||||
if os.path.isdir(vd):
|
||||
# Vagrant 1.2 (and maybe 1.1?) it's a directory tree...
|
||||
with open(os.path.join(vd, 'machines', 'default', 'virtualbox', 'id')) as vf:
|
||||
with open(os.path.join(vd, 'machines', 'default',
|
||||
'virtualbox', 'id')) as vf:
|
||||
id = vf.read()
|
||||
return id
|
||||
else:
|
||||
|
|
@ -47,6 +50,7 @@ def get_builder_vm_id():
|
|||
v = json.load(vf)
|
||||
return v['active']['default']
|
||||
|
||||
|
||||
def got_valid_builder_vm():
|
||||
"""Returns True if we have a valid-looking builder vm
|
||||
"""
|
||||
|
|
@ -59,7 +63,8 @@ def got_valid_builder_vm():
|
|||
# Vagrant 1.0 - if the directory is there, it's valid...
|
||||
return True
|
||||
# Vagrant 1.2 - the directory can exist, but the id can be missing...
|
||||
if not os.path.exists(os.path.join(vd, 'machines', 'default', 'virtualbox', 'id')):
|
||||
if not os.path.exists(os.path.join(vd, 'machines', 'default',
|
||||
'virtualbox', 'id')):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
@ -93,9 +98,12 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
|
||||
if got_valid_builder_vm():
|
||||
logging.info("...VM is present")
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'list', '--details'], cwd='builder')
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot',
|
||||
get_builder_vm_id(), 'list',
|
||||
'--details'], cwd='builder')
|
||||
if 'fdroidclean' in p.stdout:
|
||||
logging.info("...snapshot exists - resetting build server to clean state")
|
||||
logging.info("...snapshot exists - resetting build server to "
|
||||
"clean state")
|
||||
retcode, output = vagrant(['status'], cwd='builder')
|
||||
|
||||
if 'running' in output:
|
||||
|
|
@ -103,7 +111,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
vagrant(['suspend'], cwd='builder')
|
||||
logging.info("...waiting a sec...")
|
||||
time.sleep(10)
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'restore', 'fdroidclean'],
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(),
|
||||
'restore', 'fdroidclean'],
|
||||
cwd='builder')
|
||||
|
||||
if p.returncode == 0:
|
||||
|
|
@ -117,7 +126,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
else:
|
||||
logging.info("...failed to reset to snapshot")
|
||||
else:
|
||||
logging.info("...snapshot doesn't exist - VBoxManage snapshot list:\n" + p.stdout)
|
||||
logging.info("...snapshot doesn't exist - "
|
||||
"VBoxManage snapshot list:\n" + p.stdout)
|
||||
|
||||
# If we can't use the existing machine for any reason, make a
|
||||
# new one from scratch.
|
||||
|
|
@ -128,7 +138,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
shutil.rmtree('builder')
|
||||
os.mkdir('builder')
|
||||
|
||||
p = subprocess.Popen('vagrant --version', shell=True, stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen('vagrant --version', shell=True,
|
||||
stdout=subprocess.PIPE)
|
||||
vver = p.communicate()[0]
|
||||
if vver.startswith('Vagrant version 1.2'):
|
||||
with open('builder/Vagrantfile', 'w') as vf:
|
||||
|
|
@ -165,7 +176,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
elif idfile.startswith('"') and idfile.endswith('"'):
|
||||
idfile = idfile[1:-1]
|
||||
sshs.connect(sshconfig['hostname'], username=sshconfig['user'],
|
||||
port=int(sshconfig['port']), timeout=300, look_for_keys=False,
|
||||
port=int(sshconfig['port']), timeout=300,
|
||||
look_for_keys=False,
|
||||
key_filename=idfile)
|
||||
sshs.close()
|
||||
|
||||
|
|
@ -175,7 +187,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
raise BuildException("Failed to suspend build server")
|
||||
logging.info("...waiting a sec...")
|
||||
time.sleep(10)
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'take', 'fdroidclean'],
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(),
|
||||
'take', 'fdroidclean'],
|
||||
cwd='builder')
|
||||
if p.returncode != 0:
|
||||
raise BuildException("Failed to take snapshot")
|
||||
|
|
@ -188,7 +201,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
logging.info("...waiting a sec...")
|
||||
time.sleep(10)
|
||||
# Make sure it worked...
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(), 'list', '--details'],
|
||||
p = FDroidPopen(['VBoxManage', 'snapshot', get_builder_vm_id(),
|
||||
'list', '--details'],
|
||||
cwd='builder')
|
||||
if 'fdroidclean' not in p.stdout:
|
||||
raise BuildException("Failed to take snapshot.")
|
||||
|
|
@ -216,8 +230,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
if idfile.startswith('"') and idfile.endswith('"'):
|
||||
idfile = idfile[1:-1]
|
||||
sshs.connect(sshconfig['hostname'], username=sshconfig['user'],
|
||||
port=int(sshconfig['port']), timeout=300, look_for_keys=False,
|
||||
key_filename=idfile)
|
||||
port=int(sshconfig['port']), timeout=300,
|
||||
look_for_keys=False, key_filename=idfile)
|
||||
|
||||
# Get an SFTP connection...
|
||||
ftp = sshs.open_sftp()
|
||||
|
|
@ -296,7 +310,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
srclibpaths = []
|
||||
if 'srclibs' in thisbuild:
|
||||
for lib in thisbuild['srclibs']:
|
||||
srclibpaths.append(common.getsrclib(lib, 'build/srclib', srclibpaths,
|
||||
srclibpaths.append(
|
||||
common.getsrclib(lib, 'build/srclib', srclibpaths,
|
||||
basepath=True, prepare=False))
|
||||
|
||||
# If one was used for the main source, add that too.
|
||||
|
|
@ -371,6 +386,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, force):
|
|||
logging.info("Suspending build server")
|
||||
subprocess.call(['vagrant', 'suspend'], cwd='builder')
|
||||
|
||||
|
||||
def adapt_gradle(build_dir):
|
||||
for root, dirs, files in os.walk(build_dir):
|
||||
if 'build.gradle' in files:
|
||||
|
|
@ -465,6 +481,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
|
|||
logging.info("Creating source tarball...")
|
||||
tarname = common.getsrcname(app, thisbuild)
|
||||
tarball = tarfile.open(os.path.join(tmp_dir, tarname), "w:gz")
|
||||
|
||||
def tarexc(f):
|
||||
return any(f.endswith(s) for s in ['.svn', '.git', '.hg', '.bzr'])
|
||||
tarball.add(build_dir, tarname, exclude=tarexc)
|
||||
|
|
@ -603,7 +620,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
|
|||
'--name', bconfig.get('app', 'title'),
|
||||
'--package', app['id'],
|
||||
'--version', bconfig.get('app', 'version'),
|
||||
'--orientation', orientation,
|
||||
'--orientation', orientation
|
||||
]
|
||||
|
||||
perms = bconfig.get('app', 'permissions')
|
||||
|
|
@ -871,6 +888,7 @@ def parse_commandline():
|
|||
options = None
|
||||
config = None
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
global options, config
|
||||
|
|
@ -1024,4 +1042,3 @@ def main():
|
|||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue