chiark / gitweb /
Add 'fdroid gpgsign' command
[fdroidserver.git] / fdroidserver / gpgsign.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # publish.py - part of the FDroid server tools
5 # Copyright (C) 2010-2014, Ciaran Gultnieks, ciaran@ciarang.com
6 # Copyright (C) 2013-2014 Daniel Martí <mvdan@mvdan.cc>
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 import sys
22 import os
23 import shutil
24 import md5
25 import glob
26 from optparse import OptionParser
27 import logging
28
29 import common
30 import metadata
31 from common import FDroidPopen, BuildException
32
33 config = None
34 options = None
35
36
37 def main():
38
39     global config, options
40
41     # Parse command line...
42     parser = OptionParser(usage="Usage: %prog [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
43     parser.add_option("-v", "--verbose", action="store_true", default=False,
44                       help="Spew out even more information than normal")
45     parser.add_option("-q", "--quiet", action="store_true", default=False,
46                       help="Restrict output to warnings and errors")
47     (options, args) = parser.parse_args()
48
49     config = common.read_config(options)
50
51     output_dir = 'repo'
52     if not os.path.isdir(output_dir):
53         logging.error("Missing output directory")
54         sys.exit(1)
55
56     # Process any apks that are waiting to be signed...
57     for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk'))):
58
59         apkfilename = os.path.basename(apkfile)
60         sigfilename = apkfilename + ".txt"
61         sigpath = os.path.join(output_dir, sigfilename)
62
63         if not os.path.exists(sigpath):
64             p = FDroidPopen(['gpg', '-a',
65                              '--output', sigpath,
66                              '--detach-sig',
67                              os.path.join(output_dir, apkfilename)])
68             if p.returncode != 0:
69                 logging.error("Signing failed.")
70                 sys.exit(1)
71
72         logging.info('Signed ' + apkfilename)
73
74
75 if __name__ == "__main__":
76     main()