X-Git-Url: https://git.ralfj.de/auto-debuild.git/blobdiff_plain/3c40b0a24572eda4137dd92dd5abf5efaf6bb1e1..89f11516cca7f7a1e6792fe7eeef5577e740e852:/auto_debuild.py?ds=inline diff --git a/auto_debuild.py b/auto_debuild.py index 6b7a84b..eda72e3 100755 --- a/auto_debuild.py +++ b/auto_debuild.py @@ -59,8 +59,9 @@ def getArchitecture(config): if p.returncode != 0: raise Exception("Querying dpkg for the architecture failed") return res[0:len(res)-1] # chop of the \n at the end -def writeDebList(list): - return ', '.join(list) +def writeDependency(f, name, list): + if len(list): + print >>f, name+": "+', '.join(list) # actual work functions def createDebianFiles(config): @@ -76,8 +77,11 @@ def createDebianFiles(config): # we return the list of files generated, so we need to know the architecture arch = getArchitecture(config) files = [] - # source format file + # create folders + if not os.path.exists('debian'): os.mkdir('debian') if not os.path.exists('debian/source'): os.mkdir('debian/source') + if not os.path.exists(debDir): os.mkdir(debDir) + # source format file with open('debian/source/format', 'w') as f: print >>f, "3.0 (native)" # compat file @@ -99,15 +103,15 @@ def createDebianFiles(config): print >>f, "Section:",config.get('section', 'misc') print >>f, "Priority: extra" print >>f, "Maintainer: %s <%s>" % (name, email) - print >>f, "Build-Depends:",writeDebList(["debhelper (>= 9)"] + config.get('buildDepends', [])) + writeDependency(f, 'Build-Depends', ["debhelper (>= 9)"] + config.get('buildDepends', [])) print >>f, "Standards-Version: 3.9.3" print >>f, "" print >>f, "Package:",binaryName print >>f, "Architecture:",packageArchitecture - if 'binaryPreDepends' in config: - print >>f, "Pre-Depends:",writeDebList(config['binaryPreDepends']) - print >>f, "Depends:",writeDebList(["${shlibs:Depends}", "${misc:Depends}"] + config.get('binaryDepends', [])) - print >>f, "Provides:",writeDebList(config.get('binaryProvides', [sourceName])) + writeDependency(f, "Pre-Depends", ["${misc:Pre-Depends}"] + config.get('binaryPreDepends', [])) + writeDependency(f, "Depends", ["${shlibs:Depends}", "${misc:Depends}"] + config.get('binaryDepends', [])) + writeDependency(f, "Recommends", config.get('binaryRecommends', [])) + writeDependency(f, "Provides", config.get('binaryProvides', [sourceName])) print >>f, "Description:",sourceName,"(auto-debuild)" print >>f, " Package auto-generated by auto-debuild." files.append(os.path.join(debDir, "%s_%s_%s.deb" % (binaryName, version, arch))) @@ -115,7 +119,7 @@ def createDebianFiles(config): print >>f, "" print >>f, "Package:",binaryName+"-dbg" print >>f, "Architecture:",packageArchitecture - print >>f, "Depends:",writeDebList(["${misc:Depends}", binaryName+" (= ${binary:Version})"]) + writeDependency(f, "Depends", ["${misc:Depends}", binaryName+" (= ${binary:Version})"]) print >>f, "Description:",sourceName,"debug smbols (auto-debuild)" print >>f, " Package containing debug symbols for "+sourceName+", auto-generated by auto-debuild." files.append(os.path.join(debDir, "%s-dbg_%s_%s.deb" % (binaryName, version, arch))) @@ -148,22 +152,30 @@ def createDebianFiles(config): def buildDebianPackage(config): commands = ['dpkg-checkbuilddeps', 'debian/rules clean', 'debian/rules build', 'fakeroot debian/rules binary', 'debian/rules clean'] - command = ['bash', '-c', ' && '.join(commands)] + command = ['nice', 'bash', '-c', ' && '.join(commands)] subprocess.check_call(commandInBuildEnv(config, command)) -# if we are called directly as script -if __name__ == "__main__": +# all at once +def createAndInstall(config, overwriteCheck = False): # generate debian files - import imp - config = imp.load_source('config', 'debian/auto-debuild.conf').__dict__ - os.remove('debian/auto-debuild.confc') files = createDebianFiles(config) # check if a file is overwritten - for file in files: - if os.path.exists(file): - if raw_input("Do you want to overwrite %s (y/N)? " % file).lower() != "y": - sys.exit(1) + if overwriteCheck: + for file in files: + if os.path.exists(file): + if raw_input("Do you want to overwrite %s (y/N)? " % file).lower() != "y": + sys.exit(1) # run compilation buildDebianPackage(config) # install files + print "Installing created deb files..." subprocess.check_call(['sudo', 'dpkg', '--install'] + files) + +# if we are called directly as script +if __name__ == "__main__": + # get config + import imp + config = imp.load_source('config', 'debian/auto-debuild.conf').__dict__ + os.remove('debian/auto-debuild.confc') + # and go for it + createAndInstall(config, overwriteCheck=True)