mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-07-07 09:50:07 +02:00
buildserver: move code into main() method to always stop thread
By running the whole program in a main() function, it can be wrapped in try/finally in order to stop the background display thread. This is also done in ./fdroid, its standard practice for Python CLI utilities.
This commit is contained in:
parent
675500ad88
commit
6464ec55b7
@ -20,7 +20,7 @@ if not os.path.exists('makebuildserver') and not os.path.exists('buildserver'):
|
||||
|
||||
|
||||
boxfile = os.path.join(os.getcwd(), 'buildserver.box')
|
||||
serverdir = 'buildserver'
|
||||
tail = None
|
||||
|
||||
parser = OptionParser()
|
||||
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
||||
@ -293,7 +293,10 @@ def sha256_for_file(path):
|
||||
return s.hexdigest()
|
||||
|
||||
|
||||
for srcurl, shasum in cachefiles:
|
||||
def main():
|
||||
global cachedir, cachefiles, config, tail
|
||||
|
||||
for srcurl, shasum in cachefiles:
|
||||
filename = os.path.basename(srcurl)
|
||||
local_filename = os.path.join(cachedir, filename)
|
||||
|
||||
@ -345,44 +348,45 @@ for srcurl, shasum in cachefiles:
|
||||
os.remove(local_filename)
|
||||
sys.exit(1)
|
||||
|
||||
local_qt_filename = os.path.join(cachedir, 'qt-opensource-linux-x64-android-5.7.0.run')
|
||||
print("Setting executable bit for " + local_qt_filename)
|
||||
os.chmod(local_qt_filename, 0o755)
|
||||
local_qt_filename = os.path.join(cachedir, 'qt-opensource-linux-x64-android-5.7.0.run')
|
||||
print("Setting executable bit for " + local_qt_filename)
|
||||
os.chmod(local_qt_filename, 0o755)
|
||||
|
||||
# use VirtualBox software virtualization if hardware is not available,
|
||||
# like if this is being run in kvm or some other VM platform, like
|
||||
# http://jenkins.debian.net, the values are 'on' or 'off'
|
||||
if sys.platform.startswith('darwin'):
|
||||
# use VirtualBox software virtualization if hardware is not available,
|
||||
# like if this is being run in kvm or some other VM platform, like
|
||||
# http://jenkins.debian.net, the values are 'on' or 'off'
|
||||
if sys.platform.startswith('darwin'):
|
||||
# all < 10 year old Macs work, and OSX servers as VM host are very
|
||||
# rare, but this could also be auto-detected if someone codes it
|
||||
config['hwvirtex'] = 'on'
|
||||
elif os.path.exists('/proc/cpuinfo'):
|
||||
elif os.path.exists('/proc/cpuinfo'):
|
||||
with open('/proc/cpuinfo') as f:
|
||||
contents = f.read()
|
||||
if 'vmx' in contents or 'svm' in contents:
|
||||
config['hwvirtex'] = 'on'
|
||||
|
||||
logfilename = os.path.join(serverdir, 'up.log')
|
||||
if not os.path.exists(logfilename):
|
||||
serverdir = os.path.join(os.getcwd(), 'buildserver')
|
||||
logfilename = os.path.join(serverdir, 'up.log')
|
||||
if not os.path.exists(logfilename):
|
||||
open(logfilename, 'a').close() # create blank file
|
||||
log_cm = vagrant.make_file_cm(logfilename)
|
||||
v = vagrant.Vagrant(root=serverdir, out_cm=log_cm, err_cm=log_cm)
|
||||
log_cm = vagrant.make_file_cm(logfilename)
|
||||
v = vagrant.Vagrant(root=serverdir, out_cm=log_cm, err_cm=log_cm)
|
||||
|
||||
if options.verbose:
|
||||
if options.verbose:
|
||||
tail = fdroidserver.tail.Tail(logfilename)
|
||||
tail.start()
|
||||
|
||||
if options.clean:
|
||||
if options.clean:
|
||||
v.destroy()
|
||||
if config['vm_provider'] == 'libvirt':
|
||||
subprocess.call(['virsh', 'undefine', 'buildserver_default'])
|
||||
subprocess.call(['virsh', 'vol-delete', '/var/lib/libvirt/images/buildserver_default.img'])
|
||||
|
||||
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
||||
# need to create a new box:
|
||||
vf = os.path.join(serverdir, 'Vagrantfile.yaml')
|
||||
writevf = True
|
||||
if os.path.exists(vf):
|
||||
# Check against the existing Vagrantfile.yaml, and if they differ, we
|
||||
# need to create a new box:
|
||||
vf = os.path.join(serverdir, 'Vagrantfile.yaml')
|
||||
writevf = True
|
||||
if os.path.exists(vf):
|
||||
print('Halting', serverdir)
|
||||
v.halt()
|
||||
with open(vf, 'r', encoding='utf-8') as f:
|
||||
@ -393,13 +397,13 @@ if os.path.exists(vf):
|
||||
else:
|
||||
print("Re-provisioning existing server")
|
||||
writevf = False
|
||||
else:
|
||||
else:
|
||||
print("No existing server - building from scratch")
|
||||
if writevf:
|
||||
if writevf:
|
||||
with open(vf, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(config, f)
|
||||
|
||||
if config['vm_provider'] == 'libvirt':
|
||||
if config['vm_provider'] == 'libvirt':
|
||||
found_basebox = False
|
||||
needs_mutate = False
|
||||
for box in v.box_list():
|
||||
@ -422,29 +426,34 @@ if config['vm_provider'] == 'libvirt':
|
||||
print('Removing virtualbox format copy of', config['basebox'])
|
||||
v.box_remove(config['basebox'], 'virtualbox')
|
||||
|
||||
print("Configuring build server VM")
|
||||
v.up(provision=True)
|
||||
print("Configuring build server VM")
|
||||
v.up(provision=True)
|
||||
|
||||
print("Writing buildserver ID")
|
||||
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
|
||||
print("Writing buildserver ID")
|
||||
p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE,
|
||||
universal_newlines=True)
|
||||
buildserverid = p.communicate()[0].strip()
|
||||
print("...ID is " + buildserverid)
|
||||
subprocess.call(
|
||||
buildserverid = p.communicate()[0].strip()
|
||||
print("...ID is " + buildserverid)
|
||||
subprocess.call(
|
||||
['vagrant', 'ssh', '-c', 'sh -c "echo {0} >/home/vagrant/buildserverid"'
|
||||
.format(buildserverid)],
|
||||
cwd=serverdir)
|
||||
|
||||
print("Stopping build server VM")
|
||||
v.halt()
|
||||
print("Stopping build server VM")
|
||||
v.halt()
|
||||
|
||||
print("Packaging")
|
||||
v.package(output=boxfile)
|
||||
print("Packaging")
|
||||
v.package(output=boxfile)
|
||||
|
||||
print("Adding box")
|
||||
v.box_add('buildserver', boxfile, force=True)
|
||||
print("Adding box")
|
||||
v.box_add('buildserver', boxfile, force=True)
|
||||
|
||||
os.remove(boxfile)
|
||||
os.remove(boxfile)
|
||||
|
||||
if tail is not None:
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
finally:
|
||||
if tail is not None:
|
||||
tail.stop()
|
||||
|
Loading…
Reference in New Issue
Block a user