def _test_link_import(self, cfgstring, expected, cliargs, mock_exists, mock_open): data = ''' config: backup: true create: true dotpath: dotfiles banner: true longkey: false keepdot: false link_on_import: {} link_dotfile_default: nolink dotfiles: profiles: '''.format(cfgstring) mock_open.side_effect = [ unittest.mock.mock_open(read_data=data).return_value ] mock_exists.return_value = True args = _fake_args() args['--profile'] = self.PROFILE args['--cfg'] = 'mocked' args['--link'] = cliargs args['--verbose'] = True o = Options(args=args) self.assertTrue(o.import_link == expected)
def _test_link_import_fail(self, value, mock_exists, mock_open): data = ''' config: backup: true create: true dotpath: dotfiles banner: true longkey: false keepdot: false link_on_import: {} link_dotfile_default: nolink dotfiles: profiles: '''.format(value) mock_open.side_effect = [ unittest.mock.mock_open(read_data=data).return_value ] mock_exists.return_value = True args = _fake_args() args['--profile'] = 'p1' args['--cfg'] = 'mocked' args['--verbose'] = True with self.assertRaises(ValueError): o = Options(args=args) print(o.import_link)
def load_options(confpath, profile): """Load the config file from path""" # create the fake args (bypass docopt) args = _fake_args() args['--cfg'] = confpath args['--profile'] = profile args['--verbose'] = True # and get the options o = Options(args=args) o.profile = profile o.dry = False o.safe = True o.install_diff = True o.import_link = LinkTypes.NOLINK o.install_showdiff = True o.debug = True o.variables = {} return o
def main(): """entry point""" # check dependencies are met try: dependencies_met() except UnmetDependency as exc: LOG.err(exc) return False time0 = time.time() try: opts = Options() except YamlException as exc: LOG.err('config error: {}'.format(str(exc))) return False except UndefinedException as exc: LOG.err('config error: {}'.format(str(exc))) return False if opts.debug: LOG.debug = opts.debug LOG.dbg('\n\n') options_time = time.time() - time0 if opts.check_version: check_version() time0 = time.time() ret, command = _exec_command(opts) cmd_time = time.time() - time0 LOG.dbg('done executing command \"{}\"'.format(command)) LOG.dbg('options loaded in {}'.format(options_time)) LOG.dbg('command executed in {}'.format(cmd_time)) if ret and opts.conf.save(): LOG.log('config file updated') LOG.dbg('return {}'.format(ret)) return ret
def main(): """entry point""" try: o = Options() except ValueError as e: LOG.err('Config format error: {}'.format(str(e))) return False ret = True try: if o.cmd_list: # list existing profiles if o.debug: LOG.dbg('running cmd: list') cmd_list_profiles(o) elif o.cmd_listfiles: # list files for selected profile if o.debug: LOG.dbg('running cmd: listfiles') cmd_list_files(o) elif o.cmd_install: # install the dotfiles stored in dotdrop if o.debug: LOG.dbg('running cmd: install') ret = cmd_install(o) elif o.cmd_compare: # compare local dotfiles with dotfiles stored in dotdrop if o.debug: LOG.dbg('running cmd: compare') tmp = get_tmpdir() ret = cmd_compare(o, tmp) # clean tmp directory remove(tmp) elif o.cmd_import: # import dotfile(s) if o.debug: LOG.dbg('running cmd: import') ret = cmd_importer(o) elif o.cmd_update: # update a dotfile if o.debug: LOG.dbg('running cmd: update') ret = cmd_update(o) elif o.cmd_detail: # detail files if o.debug: LOG.dbg('running cmd: update') cmd_detail(o) except KeyboardInterrupt: LOG.err('interrupted') ret = False return ret
def main(): """entry point""" # check dependencies are met try: dependencies_met() except Exception as e: LOG.err(e) return False t0 = time.time() try: o = Options() except YamlException as e: LOG.err('config error: {}'.format(str(e))) return False except UndefinedException as e: LOG.err('config error: {}'.format(str(e))) return False if o.debug: LOG.dbg('\n\n') options_time = time.time() - t0 ret = True t0 = time.time() command = '' try: if o.cmd_profiles: # list existing profiles command = 'profiles' if o.debug: LOG.dbg('running cmd: {}'.format(command)) cmd_list_profiles(o) elif o.cmd_files: # list files for selected profile command = 'files' if o.debug: LOG.dbg('running cmd: {}'.format(command)) cmd_files(o) elif o.cmd_install: # install the dotfiles stored in dotdrop command = 'install' if o.debug: LOG.dbg('running cmd: {}'.format(command)) ret = cmd_install(o) elif o.cmd_compare: # compare local dotfiles with dotfiles stored in dotdrop command = 'compare' if o.debug: LOG.dbg('running cmd: {}'.format(command)) tmp = get_tmpdir() ret = cmd_compare(o, tmp) # clean tmp directory removepath(tmp, LOG) elif o.cmd_import: # import dotfile(s) command = 'import' if o.debug: LOG.dbg('running cmd: {}'.format(command)) ret = cmd_importer(o) elif o.cmd_update: # update a dotfile command = 'update' if o.debug: LOG.dbg('running cmd: {}'.format(command)) ret = cmd_update(o) elif o.cmd_detail: # detail files command = 'detail' if o.debug: LOG.dbg('running cmd: {}'.format(command)) cmd_detail(o) elif o.cmd_remove: # remove dotfile command = 'remove' if o.debug: LOG.dbg('running cmd: {}'.format(command)) cmd_remove(o) except KeyboardInterrupt: LOG.err('interrupted') ret = False cmd_time = time.time() - t0 if o.debug: LOG.dbg('done executing command \"{}\"'.format(command)) LOG.dbg('options loaded in {}'.format(options_time)) LOG.dbg('command executed in {}'.format(cmd_time)) if ret and o.conf.save(): LOG.log('config file updated') if o.debug: LOG.dbg('return {}'.format(ret)) return ret
def load_options(confpath, profile): """Load the config file from path""" # create the fake args (bypass docopt) args = _fake_args() args['--cfg'] = confpath args['--profile'] = profile # and get the options # TODO need to patch options o = Options(args=args) o.profile = profile o.dry = False o.profile = profile o.safe = True o.install_diff = True o.link = LinkTypes.NOLINK.value o.install_showdiff = True o.debug = True o.compare_dopts = '' o.variables = {} return o
def main(): """entry point""" try: o = Options() except YamlException as e: LOG.err('config file error: {}'.format(str(e))) return False if o.debug: LOG.dbg('\n\n') # check dependencies are met try: dependencies_met() except Exception as e: LOG.err(e) return False ret = True try: if o.cmd_profiles: # list existing profiles if o.debug: LOG.dbg('running cmd: profiles') cmd_list_profiles(o) elif o.cmd_files: # list files for selected profile if o.debug: LOG.dbg('running cmd: files') cmd_list_files(o) elif o.cmd_install: # install the dotfiles stored in dotdrop if o.debug: LOG.dbg('running cmd: install') ret = cmd_install(o) elif o.cmd_compare: # compare local dotfiles with dotfiles stored in dotdrop if o.debug: LOG.dbg('running cmd: compare') tmp = get_tmpdir() ret = cmd_compare(o, tmp) # clean tmp directory remove(tmp) elif o.cmd_import: # import dotfile(s) if o.debug: LOG.dbg('running cmd: import') ret = cmd_importer(o) elif o.cmd_update: # update a dotfile if o.debug: LOG.dbg('running cmd: update') ret = cmd_update(o) elif o.cmd_detail: # detail files if o.debug: LOG.dbg('running cmd: detail') cmd_detail(o) elif o.cmd_remove: # remove dotfile if o.debug: LOG.dbg('running cmd: remove') cmd_remove(o) except KeyboardInterrupt: LOG.err('interrupted') ret = False if ret and o.conf.save(): LOG.log('config file updated') return ret