def __init__(self, config=None): # Configuration data self.config = None # Version manifest file self.version_data = None # Specifies if the config file needs to be loaded self.config_loaded = False # Used to store config information self.db = Storage() if config: # Support for creating patches self.patch_support = config.get("UPDATE_PATCHES", True) is True else: self.patch_support = False # References the pyu-data folder in the root of repo self.data_dir = os.path.join(os.getcwd(), settings.USER_DATA_FOLDER) self.files_dir = os.path.join(self.data_dir, "files") self.deploy_dir = os.path.join(self.data_dir, "deploy") self.new_dir = os.path.join(self.data_dir, "new") self.config_dir = os.path.join(os.getcwd(), settings.CONFIG_DATA_FOLDER) self.setup()
def __init__(self): self.db = Storage() self.key_encoding = "base64" data_dir = os.getcwd() self.data_dir = os.path.join(data_dir, settings.USER_DATA_FOLDER) self.deploy_dir = os.path.join(self.data_dir, "deploy") # Name of the keypack to import. It should be placed # in the root of the repo self.keypack_filename = os.path.join( data_dir, settings.CONFIG_DATA_FOLDER, settings.KEYPACK_FILENAME ) # The name of the gzipped version file in # the pyu-data/deploy directory self.version_file = os.path.join( self.deploy_dir, settings.VERSION_FILE_FILENAME ) self.version_file_compat = os.path.join( self.deploy_dir, settings.VERSION_FILE_FILENAME_COMPAT ) # The name of the gzipped key file in # the pyu-data/deploy directory self.key_file = os.path.join(self.deploy_dir, settings.KEY_FILE_FILENAME)
def update(args): # pragma: no cover check_repo() db = Storage() loader = Loader(db) log.info('Starting repo update') config = loader.load_config() repo_update(config) loader.save_config(config) log.info('Reconfig complete') db._sync_db()
def test_add(self): db = Storage() keydb = KeyDB(db, load=True) db._sync_db() assert len(os.listdir(os.getcwd())) == 1 keydb.add_key('public1', 'private1') keydb.add_key('public2', 'private2') assert len(keydb.get_public_keys()) == 2 assert keydb.get_public_keys()[0] == 'public1' assert keydb.get_public_keys()[1] == 'public2'
def test_get_revoked_key(self): db = Storage() keydb = KeyDB(db, load=True) db._sync_db() assert len(os.listdir(os.getcwd())) == 1 assert keydb.get_revoked_key() is None keydb.add_key('public1', 'private1') keydb.add_key('public2', 'private2') assert len(keydb.get_public_keys()) == 2 keydb.revoke_key(count=2) assert len(keydb.get_public_keys()) == 0
def test_revoking_break(self): db = Storage() keydb = KeyDB(db, load=False) db._sync_db() assert len(os.listdir(os.getcwd())) == 1 keydb.add_key('public1', 'private1') keydb.add_key('public2', 'private2') assert keydb.get_revoked_key() is None assert len(keydb.get_public_keys()) == 2 keydb.revoke_key(count=1) assert len(keydb.get_public_keys()) == 1 assert keydb.get_revoked_key()['public'] == 'public1'
def __init__(self, config=None): # References the pyu-data folder in the root of repo self.data_dir = None # Specifies if the config file needs to be loaded self.config_loaded = False # Used to store config information self.db = Storage() # Initialize app if config is available if config is not None: self.init_app(config)
def __init__(self): self.db = Storage() self.key_encoding = 'base64' data_dir = os.getcwd() self.data_dir = os.path.join(data_dir, settings.USER_DATA_FOLDER) self.deploy_dir = os.path.join(self.data_dir, 'deploy') self.keypack_filename = os.path.join(data_dir, settings.CONFIG_DATA_FOLDER, settings.KEYPACK_FILENAME) self.version_file = os.path.join(self.deploy_dir, settings.VERSION_FILE) self.key_file = os.path.join(self.deploy_dir, settings.KEY_FILE)
def pkg(args): check_repo() db = Storage() loader = Loader(db) pyu = PyUpdater(loader.load_config(), db) if args.process is False and args.sign is False: sys.exit('You must specify a command') if args.process is True: log.info('Processing packages...') pyu.process_packages() log.info('Processing packages complete') if args.sign is True: log.info('Signing packages...') pyu.sign_update() log.info('Signing packages complete') db._sync_db()
def update_config(self, config, db): """Updates internal config Args: config (obj): config object """ if not hasattr(config, 'DATA_DIR'): config.DATA_DIR = None if config.DATA_DIR is None: config.DATA_DIR = os.getcwd() if db is None: self.db = Storage(config.DATA_DIR) else: self.db = db self.config.from_object(config) self._update(self.config, self.db)
def _setting(args): # pragma: no cover check_repo() db = Storage() loader = Loader(db) config = loader.load_config() if args.appname is True: setup_appname(config) if args.company is True: setup_company(config) if args.urls is True: setup_urls(config) if args.patches is True: setup_patches(config) if args.scp is True: setup_scp(config) if args.s3 is True: setup_object_bucket(config) loader.save_config(config) log.info('Settings update complete') db._sync_db()
def upload(args): # pragma: no cover error = False check_repo() db = Storage() loader = Loader(db) upload_service = args.service if upload_service is None: log.error('Must provide service name') error = True if error is False: pyu = PyUpdater(loader.load_config(), db) try: pyu.set_uploader(upload_service) except UploaderError as err: log.error(str(err)) error = True except UploaderPluginError as err: log.debug(str(err)) error = True mgr = stevedore.ExtensionManager(settings.UPLOAD_PLUGIN_NAMESPACE) plugin_names = mgr.names() log.debug('Plugin names: {}'.format(plugin_names)) if len(plugin_names) == 0: msg = ('*** No upload plugins instaled! ***\nYou can install ' 'the aws s3 plugin with\n$ pip install PyUpdater' '[s3]\n\nOr the scp plugin with\n$ pip install ' 'PyUpdater[scp]') else: msg = ('Invalid Uploader\n\nAvailable options:\n' '{}'.format(' '.join(plugin_names))) log.error(msg) if error is False: try: pyu.upload() except Exception as e: msg = ('Looks like you forgot to add USERNAME ' 'and/or REMOTE_DIR') log.debug(str(e), exc_info=True) log.error(msg) db._sync_db()
def init(args): # pragma: no cover db = Storage() loader = Loader(db) count = args.count if count > 10: sys.exit('Cannot be more then 10') if not os.path.exists( os.path.join(settings.CONFIG_DATA_FOLDER, settings.CONFIG_FILE_USER)): config = initial_setup(SetupConfig()) log.info('Creating pyu-data dir...') pyu = PyUpdater(config, db) pyu.setup() log.info('Making signing keys...') pyu.make_keys(count) config.PUBLIC_KEYS = pyu.get_public_keys() loader.save_config(config) log.info('Setup complete') db._sync_db() else: sys.exit('Not an empty PyUpdater repository')
def _keys(args): # pragma: no cover check_repo() db = Storage() loader = Loader(db) config = loader.load_config() pyu = PyUpdater(config, db) if args.count is not None: count = args.count pyu.revoke_key(count) config.PUBLIC_KEYS = pyu.get_public_keys() key = pyu.get_recent_revoked_key() if key is not None: log.info('* Most Recent Revoked Key *') log.info('Created: {}'.format(pretty_time(key['date']))) log.info('Type: {}'.format(key['key_type'])) log.info('Public Key: {}'.format(key['public'])) if args.private is True: log.info('Private Key: {}'.format(key['private'])) else: log.info('Private Key: * Next time to show private key ' 'use --show-private *') loader.save_config(config) db._sync_db()
def db(): db = Storage() return db
def __init__(self): self.cwd = os.getcwd() self.db = Storage() self.config_key = settings.CONFIG_DB_KEY_APP_CONFIG
def __init__(self): self.db = Storage()
def __init__(self): self.cwd = os.getcwd() self.db = Storage() self.password = os.environ.get(settings.USER_PASS_ENV) self.config_key = settings.CONFIG_DB_KEY_APP_CONFIG
def __init__(self, config=None): self.config_loaded = False self.db = Storage() if config is not None: self.init_app(config)