-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
#
# server.py - part of the FDroid server tools
# Copyright (C) 2010-15, Ciaran Gultnieks, ciaran@ciarang.com
import paramiko
import pwd
import subprocess
-from optparse import OptionParser
+from argparse import ArgumentParser
import logging
import common
global config, options
# Parse command line...
- parser = OptionParser()
- parser.add_option("-i", "--identity-file", default=None,
- help="Specify an identity file to provide to SSH for rsyncing")
- parser.add_option("--local-copy-dir", default=None,
- help="Specify a local folder to sync the repo to")
- parser.add_option("--sync-from-local-copy-dir", action="store_true", default=False,
- help="Before uploading to servers, sync from local copy dir")
- parser.add_option("-v", "--verbose", action="store_true", default=False,
- help="Spew out even more information than normal")
- parser.add_option("-q", "--quiet", action="store_true", default=False,
- help="Restrict output to warnings and errors")
- parser.add_option("--no-checksum", action="store_true", default=False,
- help="Don't use rsync checksums")
- (options, args) = parser.parse_args()
+ parser = ArgumentParser()
+ common.setup_global_opts(parser)
+ parser.add_argument("command", help="command to execute, either 'init' or 'update'")
+ parser.add_argument("-i", "--identity-file", default=None,
+ help="Specify an identity file to provide to SSH for rsyncing")
+ parser.add_argument("--local-copy-dir", default=None,
+ help="Specify a local folder to sync the repo to")
+ parser.add_argument("--sync-from-local-copy-dir", action="store_true", default=False,
+ help="Before uploading to servers, sync from local copy dir")
+ parser.add_argument("--no-checksum", action="store_true", default=False,
+ help="Don't use rsync checksums")
+ options = parser.parse_args()
config = common.read_config(options)
- if len(args) != 1:
- logging.critical("Specify a single command")
- sys.exit(1)
-
- if args[0] != 'init' and args[0] != 'update':
+ if options.command != 'init' and options.command != 'update':
logging.critical("The only commands currently supported are 'init' and 'update'")
sys.exit(1)
if config['per_app_repos']:
repo_sections += common.get_per_app_repos()
- if args[0] == 'init':
+ if options.command == 'init':
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
for serverwebroot in config.get('serverwebroot', []):
sftp.mkdir(repo_path, mode=0755)
sftp.close()
ssh.close()
- elif args[0] == 'update':
+ elif options.command == 'update':
for repo_section in repo_sections:
if local_copy_dir is not None:
if config['sync_from_local_copy_dir'] and os.path.exists(repo_section):