PageRenderTime 41ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/fdroidserver/gpgsign.py

https://gitlab.com/krt/fdroidserver
Python | 78 lines | 44 code | 15 blank | 19 comment | 11 complexity | 4f732da14ef1c1236c9bfae03e2c1b5b MD5 | raw file
Possible License(s): AGPL-3.0
  1. #!/usr/bin/env python3
  2. #
  3. # gpgsign.py - part of the FDroid server tools
  4. # Copyright (C) 2014, Ciaran Gultnieks, ciaran@ciarang.com
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. import os
  19. import glob
  20. from argparse import ArgumentParser
  21. import logging
  22. from . import common
  23. from .common import FDroidPopen
  24. from .exception import FDroidException
  25. config = None
  26. options = None
  27. def main():
  28. global config, options
  29. # Parse command line...
  30. parser = ArgumentParser(usage="%(prog)s [options]")
  31. common.setup_global_opts(parser)
  32. options = parser.parse_args()
  33. config = common.read_config(options)
  34. repodirs = ['repo']
  35. if config['archive_older'] != 0:
  36. repodirs.append('archive')
  37. for output_dir in repodirs:
  38. if not os.path.isdir(output_dir):
  39. raise FDroidException("Missing output directory '" + output_dir + "'")
  40. # Process any apks that are waiting to be signed...
  41. for f in sorted(glob.glob(os.path.join(output_dir, '*.*'))):
  42. if common.get_file_extension(f) == 'asc':
  43. continue
  44. if not common.is_repo_file(f):
  45. continue
  46. filename = os.path.basename(f)
  47. sigfilename = filename + ".asc"
  48. sigpath = os.path.join(output_dir, sigfilename)
  49. if not os.path.exists(sigpath):
  50. gpgargs = ['gpg', '-a',
  51. '--output', sigpath,
  52. '--detach-sig']
  53. if 'gpghome' in config:
  54. gpgargs.extend(['--homedir', config['gpghome']])
  55. if 'gpgkey' in config:
  56. gpgargs.extend(['--local-user', config['gpgkey']])
  57. gpgargs.append(os.path.join(output_dir, filename))
  58. p = FDroidPopen(gpgargs)
  59. if p.returncode != 0:
  60. raise FDroidException("Signing failed.")
  61. logging.info('Signed ' + filename)
  62. if __name__ == "__main__":
  63. main()