1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-03 17:50:11 +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:
Hans-Christoph Steiner 2016-09-25 18:55:29 +02:00
parent 675500ad88
commit 6464ec55b7

View File

@ -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,6 +293,9 @@ def sha256_for_file(path):
return s.hexdigest()
def main():
global cachedir, cachefiles, config, tail
for srcurl, shasum in cachefiles:
filename = os.path.basename(srcurl)
local_filename = os.path.join(cachedir, filename)
@ -362,6 +365,7 @@ elif os.path.exists('/proc/cpuinfo'):
if 'vmx' in contents or 'svm' in contents:
config['hwvirtex'] = 'on'
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
@ -446,5 +450,10 @@ v.box_add('buildserver', boxfile, force=True)
os.remove(boxfile)
if __name__ == '__main__':
try:
main()
finally:
if tail is not None:
tail.stop()