+#---------------------------------------------------------
+# Generates Packages, Sources and Release files of debian package
+#---------------------------------------------------------
+def gen_deb_package(o, published_files):
+ # Executes command to produce file_name in path, and moves it to o.pub/deb
+ def _gen_file(o, (command, file_name), path):
+ cur_tmp_file_path = os.path.join(path, file_name)
+ with open(cur_tmp_file_path, 'w') as out:
+ subprocess.call(command, stdout=out, cwd=path)
+ system(['cp', cur_tmp_file_path, os.path.join(o.pub, 'deb', file_name)])
+
+ # Copy files to a temp directory (required because the working directory must contain only the files of the last release)
+ temp_path = tempfile.mkdtemp(suffix='debPackages')
+ for pub_file_path in published_files:
+ system(['cp', pub_file_path, temp_path])
+
+ commands = [
+ (['dpkg-scanpackages', '.'], "Packages"), # Generate Packages file
+ (['dpkg-scansources', '.'], "Sources"), # Generate Sources file
+ (['apt-ftparchive', 'release', '.'], "Release") # Generate Release file
+ ]
+ # Generate files
+ for command in commands:
+ _gen_file(o, command, temp_path)
+ # Remove temp directory
+ shutil.rmtree(temp_path)
+
+ # Generate Release.gpg (= signed Release)
+ # Options -abs: -a (Create ASCII armored output), -b (Make a detach signature), -s (Make a signature)
+ subprocess.call(['rm', 'Release.gpg'], cwd=os.path.join(o.pub, 'deb'))
+ subprocess.call(['gpg', '-abs', '-o', 'Release.gpg', 'Release'], cwd=os.path.join(o.pub, 'deb'))
+