def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument('op', action="store", choices=['add', 'del', 'subscribe', 'unsubscribe'], help="Operation") group = parser.add_argument_group('Common parameters') group.add_argument('--confdir', action="store", help="Customized certificates directory", default=utils.get_basedir_default()) group.add_argument('--debug', action="store_true", help="Enable debugging") group = parser.add_argument_group('Operations: add, del') group.add_argument('--cert', action="store", help="Certificate file", default="") group.add_argument('--name', action="store", help="Name of the link") group.add_argument('--url', action="store", help="URL to the uplink host") group = parser.add_argument_group('Operations: subscribe, unsubscribe') group.add_argument('--channel', action="store", help="Subscribe to a channel", metavar="NAME") ns = parser.parse_args() if ns.debug: logging.basicConfig(level=logging.DEBUG) # # Links # if ns.op == 'add': utils.assert_cli_args(['name', 'cert'], ns) config = Config.Config(ns.confdir) config.link_add(ns.cert, ns.name, ns.url) config.save() elif ns.op == 'del': utils.assert_cli_args(['name'], ns) config = Config.Config(ns.confdir) config.link_del(ns.name) config.save() # # Subscriptions # elif ns.op == 'subscribe': utils.assert_cli_args(['name', 'channel'], ns) config = Config.Config(ns.confdir) config.link_add_subscription(ns.name, ns.channel) config.save() elif ns.op == 'unsubscribe': utils.assert_cli_args(['name', 'channel'], ns) config = Config.Config(ns.confdir) config.link_del_subscription(ns.name, ns.channel) config.save()
def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument ('--confdir', action="store", help="Customized certificates directory", default=utils.get_basedir_default()) parser.add_argument ('--debug', action="store_true", help="Enable debugging") parser.add_argument ('--list' , action="store_true", help="List keys") parser.add_argument ('--id', action="store_true", help="Get the key ID instead of the armored key") ns = parser.parse_args() if ns.debug: logging.basicConfig (level = logging.DEBUG) # Key manager keys = Keys.Manager (ns.confdir) # Print list if ns.list: print_keys(keys) raise SystemExit if ns.id: print keys.get_gpg_public_keyid() raise SystemExit # Public key bundle li = LinkInfo.LinkInfo() print li.get_uplink_info(ns.confdir)
def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument ('ID', action="store", help="ID of the link to ping") parser.add_argument ('--confdir', action="store", help="Customized certificates directory", default=utils.get_basedir_default()) parser.add_argument ('--debug', action="store_true", help="Enable debugging") ns = parser.parse_args() if ns.debug: logging.basicConfig (level = logging.DEBUG) # Config config = Config.Config (ns.confdir) # Key manager keys = Keys.Manager (ns.confdir) # Client ping = Client.Ping (config, keys, ns.ID) n = 5 while n > 0: ping.execute() time.sleep(1) n -= 1
def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument ('op', action="store", choices=['add', 'del', 'subscribe', 'unsubscribe'], help="Operation") group = parser.add_argument_group('Common parameters') group.add_argument ('--confdir', action="store", help="Customized certificates directory", default=utils.get_basedir_default()) group.add_argument ('--debug', action="store_true", help="Enable debugging") group = parser.add_argument_group('Operations: add, del') group.add_argument ('--cert', action="store", help="Certificate file", default="") group.add_argument ('--name', action="store", help="Name of the link") group.add_argument ('--url', action="store", help="URL to the uplink host") group = parser.add_argument_group('Operations: subscribe, unsubscribe') group.add_argument ('--channel', action="store", help="Subscribe to a channel", metavar="NAME") ns = parser.parse_args() if ns.debug: logging.basicConfig (level = logging.DEBUG) # # Links # if ns.op == 'add': utils.assert_cli_args (['name', 'cert'], ns) config = Config.Config (ns.confdir) config.link_add (ns.cert, ns.name, ns.url) config.save() elif ns.op == 'del': utils.assert_cli_args (['name'], ns) config = Config.Config (ns.confdir) config.link_del (ns.name) config.save() # # Subscriptions # elif ns.op == 'subscribe': utils.assert_cli_args (['name', 'channel'], ns) config = Config.Config (ns.confdir) config.link_add_subscription (ns.name, ns.channel) config.save() elif ns.op == 'unsubscribe': utils.assert_cli_args (['name', 'channel'], ns) config = Config.Config (ns.confdir) config.link_del_subscription (ns.name, ns.channel) config.save()
def main(): default_name = utils.get_default_name() default_email = utils.get_default_email() # Argument parsing parser = argparse.ArgumentParser() parser.add_argument('--confdir', action="store", help="Customized certificates directory", default=utils.get_basedir_default()) parser.add_argument('--downloads', action="store", help="Downloads directory", default=utils.get_downloads_default()) parser.add_argument('--debug', action="store_true", help="Enable debugging") parser.add_argument('--force', action="store_true", help="Force operation") parser.add_argument('--name', action="store", help="Your name (Default: %s)" % (default_name), default=default_name) parser.add_argument('--email', action="store", help="Your email (Default: %s)" % (default_email), default=default_email) parser.add_argument('--public_url', action="store", help="Address clients connect to") ns = parser.parse_args() if ns.debug: logging.basicConfig(level=logging.DEBUG) # Already inited? gpg_dir = os.path.join(ns.confdir, 'gpg') if os.path.exists(gpg_dir) and not ns.force: print >> sys.stderr, "ERROR: Directory exists %s" % (ns.confdir) raise SystemExit # Create GPG keys keys = Keys.Manager(ns.confdir) keys.keys_gpg_create(ns.email, name=ns.name) keys.keys_https_create() # Download directory if not os.path.exists(ns.downloads): os.makedirs(ns.downloads, 0700) # Configuration file config_fp = utils.get_config_fp(ns.confdir) with open(config_fp, 'w+') as f: f.write(CFG_EXAMPLE) # Add configuration paramaters config = Config.Config(ns.confdir) config.config['downloads'] = ns.downloads if ns.public_url: config.config['public_url'] = ns.public_url config.save()
def main(): default_name = utils.get_default_name() default_email = utils.get_default_email() # Argument parsing parser = argparse.ArgumentParser() parser.add_argument( "--confdir", action="store", help="Customized certificates directory", default=utils.get_basedir_default() ) parser.add_argument( "--downloads", action="store", help="Downloads directory", default=utils.get_downloads_default() ) parser.add_argument("--debug", action="store_true", help="Enable debugging") parser.add_argument("--force", action="store_true", help="Force operation") parser.add_argument("--name", action="store", help="Your name (Default: %s)" % (default_name), default=default_name) parser.add_argument( "--email", action="store", help="Your email (Default: %s)" % (default_email), default=default_email ) parser.add_argument("--public_url", action="store", help="Address clients connect to") ns = parser.parse_args() if ns.debug: logging.basicConfig(level=logging.DEBUG) # Already inited? gpg_dir = os.path.join(ns.confdir, "gpg") if os.path.exists(gpg_dir) and not ns.force: print >>sys.stderr, "ERROR: Directory exists %s" % (ns.confdir) raise SystemExit # Create GPG keys keys = Keys.Manager(ns.confdir) keys.keys_gpg_create(ns.email, name=ns.name) keys.keys_https_create() # Download directory if not os.path.exists(ns.downloads): os.makedirs(ns.downloads, 0700) # Configuration file config_fp = utils.get_config_fp(ns.confdir) with open(config_fp, "w+") as f: f.write(CFG_EXAMPLE) # Add configuration paramaters config = Config.Config(ns.confdir) config.config["downloads"] = ns.downloads if ns.public_url: config.config["public_url"] = ns.public_url config.save()
def main(): # Argument parsing parser = argparse.ArgumentParser() parser.add_argument ('op', action="store", choices=['server', 'channels', 'ls', 'download', 'sync', 'client', 'run'], help="Operation") group = parser.add_argument_group('Common parameters') group.add_argument ('--confdir', action="store", help="Customized configuration directory", default=utils.get_basedir_default()) group.add_argument ('--debug', action="store_true", help="Enable debugging") group = parser.add_argument_group('Server') group.add_argument ('--port', action="store", help="Customized HTTPS port (Default: 443)", type=int) group.add_argument ('--key', action="store_true", help="Serve public key from /key") group = parser.add_argument_group('Client') group.add_argument ('--downloads', action="store", help="Downloads directory", metavar="PATH", default=utils.get_downloads_default()) group.add_argument ('--name', action="store", help="Name of the host to connect to") group.add_argument ('--channels', action="store", help="Channels", metavar="NAMES") group.add_argument ('--file', action="store", help="Filename") ns = parser.parse_args() if ns.debug: logging.basicConfig (level = logging.DEBUG) # Key manager keys = Keys.Manager (ns.confdir) # Config config = Config.Config (ns.confdir) # Channels channels = Channels.Manager (config) # Server if ns.op == 'server': srv = HTTPS.Server (keys, channels, config, ns.port, ns.key) srv.run() # Client elif ns.op == 'channels': utils.assert_cli_args (['name'], ns) lst = Client.ChannelList (config, keys, ns.name) channels = lst.execute() for channel in channels: print (channel) elif ns.op == 'ls': utils.assert_cli_args (['name','channels'], ns) lst = Client.FileList (config, keys, ns.name, ns.channels) files = lst.execute() for f in files: print ("%s (%s) size=%s" %(f['path'], f['md5'], f['size'])) elif ns.op == 'download': time_start = time.time() def step_callback(downloaded): lapse = time.time() - time_start print "%s: %s (%s/s)%s\r" %(ns.file, utils.format_size(downloaded), utils.format_size(downloaded/lapse), ' '*10), utils.assert_cli_args (['name','channels', 'file'], ns) dwn = Client.Download (config, ns.downloads, keys, ns.name, ns.channels, ns.file, step_callback) dwn.execute() elif ns.op == 'sync': utils.assert_cli_args (['name'], ns) sync = Client.Sync (config, ns.downloads, keys, ns.name) sync.execute() elif ns.op == 'client': utils.assert_cli_args (['name'], ns) client = Client.Client (config, ns.downloads, keys, ns.name) client.execute() # Server + Client elif ns.op == 'run': client_server = Client.Client_Server (config, ns.downloads, keys, channels, ns.port, ns.key) client_server.execute()