def clean_cmd(): """This function is launched when the ``vimpck clean`` command is invoked. """ vimpckrc = utils.ConfigFile() plugls = utils.DiskPlugin(vimpckrc.pack_path) diff = set(vimpckrc.rem_urls).symmetric_difference( set(plugls.all_plug.values())) if not diff: sys.exit("no plugins to be removed!") ansi_tran = ansi.Parser(const.LHS, const.RHS) title = "<bold>:: Removing {} plugin(s)...<reset>".format(len(diff)) print(ansi_tran.sub(title)) for rem_url in diff: plug = [k for k, v in plugls.all_plug.items() if v == rem_url][0] info = "Removing {}".format(plug) a_spinner = spinner.Spinner(info, const.INTERVAL, const.SEQUENCE, const.OFFSET) a_spinner.start() try: shutil.rmtree(os.path.join(vimpckrc.pack_path, plug)) pass except: status = "✗ {}: <red>Could not remove!<reset>".format(info) else: status = "Removed" status = "✓ {}: <green>{}<reset>".format(info, status) a_spinner.stop() status = status.rjust(len(status) + const.OFFSET) print(ansi_tran.sub(status)) del a_spinner
def install_cmd(): """Install function. This function is launched when the ``vimpck install`` command is invoked. """ vimpckrc = utils.ConfigFile() os.makedirs(vimpckrc.pack_path, exist_ok=True) pluglist = utils.DiskPlugin(vimpckrc.pack_path) diff = set(vimpckrc.freeze_false()).symmetric_difference( set(pluglist.all_plug.values())) if not diff: print('no plugin to install !') else: ansi_tran = ansi.Parser(const.LHS, const.RHS) title = "<bold>:: Installing plugins...<reset>" print(ansi_tran.sub(title)) for remote_url in diff: info = "{}".format(remote_url) a_spinner = spinner.Spinner(info, const.INTERVAL, const.SEQUENCE, const.OFFSET) local_dir = os.path.join( vimpckrc.pack_path, vimpckrc.config[const.SECT_2][remote_url][const.PKG_NAME], vimpckrc.config[const.SECT_2][remote_url][const.TYPE_NAME]) os.makedirs(local_dir, exist_ok=True) tmp_cloner = git.Clone(remote_url, local_dir) a_spinner.start() out = tmp_cloner.git_cmd() a_spinner.stop() if out == 0: status = "✓ {}: <green>Installed<reset>".format(info) status = status.rjust(len(status) + const.OFFSET) status = ansi_tran.sub(status) print(status) else: status = "✗ {}: <red>Fail<reset>".format(info) status = status.rjust(len(status) + const.OFFSET) status = ansi_tran.sub(status) print(status) err_status = tmp_cloner.error_proc.stderr.decode('UTF-8') # TODO: duplicate the retrieve_stdout method, merge them err_status = err_status.rjust( len(err_status) + const.OFFSET + 2) print(err_status) del a_spinner del tmp_cloner
def test_install_4_fake_plugin_no_problem(self, temp_dir): """ Simulate installing 4 plugins by creating 4 git folder and assigning them a fake remote url. Then use the DiskPlugin to get the dictionary of plugin and make a comparison between what has been installed and what is retrieve """ bsdir = str(temp_dir.mktemp("test_DiskPlugin_class")) plugins = { 'colors/start/vim-colors-solarized': 'fake_url1', 'filetype/opt/vim-mustache-handlebars': 'fake_url2', 'filetype/start/vim-dispatch': 'fake_url3', 'common/start/vim-commentary': 'fake_url4' } for key in plugins: local_dir = os.path.join(bsdir, key) os.makedirs(local_dir) cmd = ["git", "-C", local_dir, "init"] subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) cmd = [ "git", "-C", local_dir, "remote", "add", "origin", plugins[key] ] subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) plugls = utils.DiskPlugin(bsdir) if not set(plugls.all_plug.keys()).symmetric_difference( set(plugins.keys())): assert 1 else: assert 0 if not set(plugls.all_plug.values()).symmetric_difference( set(plugins.values())): assert 1 else: assert 0
def ls_cmd(**kwargs): """list function. This function is launched when the ``vimpck ls`` command is invoked. Arg: **kwarg (str) : an argument is present, kwargs['start']/kwarg['opt'] to filter autostart/optional plugins """ vimpckrc = utils.ConfigFile() if not os.path.isdir(vimpckrc.pack_path): sys.exit("{} does not exist. Use vimpck install".format( vimpckrc.pack_path)) plugls = utils.DiskPlugin(vimpckrc.pack_path) if kwargs['start']: plug = plugls.filt_plug('start') elif kwargs['opt']: plug = plugls.filt_plug('opt') else: plug = plugls.all_plug.keys() return plug
def remove_cmd(**kwargs): """This function is launched when the ``vimpck remove`` command is invoked. """ vimpckrc = utils.ConfigFile() plugls = utils.DiskPlugin(vimpckrc.pack_path) ansi_tran = ansi.Parser(const.LHS, const.RHS) title = "<bold>:: Removing {} plugin(s)...<reset>".format( len(kwargs['plug'])) print(ansi_tran.sub(title)) for plug in kwargs['plug']: info = "Removing {}".format(plug) a_spinner = spinner.Spinner(info, const.INTERVAL, const.SEQUENCE, const.OFFSET) a_spinner.start() if plug in plugls.all_plug.keys(): try: shutil.rmtree(os.path.join(vimpckrc.pack_path, plug)) except: status = "✗ {}: <red>Could not remove !<reset>".format(info) else: status = "Removed" status = "✓ {}: <green>{}<reset>".format(info, status) if kwargs['r']: vimpckrc.config[const.SECT_2].pop(plugls.all_plug[plug], None) vimpckrc.config.write() else: status = "✗ {}: <red>Not a valid plugin !<reset>".format(info) a_spinner.stop() status = status.rjust(len(status) + const.OFFSET) print(ansi_tran.sub(status)) del a_spinner
def upgrade_cmd(**kwargs): """Upgrade function. This function is launched when the ``vimpck upgrade`` command is invoked. """ vimpckrc = utils.ConfigFile() os.makedirs(vimpckrc.pack_path, exist_ok=True) pluglist = utils.DiskPlugin(vimpckrc.pack_path) plug = { k: v for k, v in pluglist.all_plug.items() if v in vimpckrc.freeze_false() } if kwargs['plug']: plug = { k: v for k, v in pluglist.all_plug.items() if k in kwargs['plug'] } if not plug: sys.exit('no plugins to be upgraded!') ansi_tran = ansi.Parser(const.LHS, const.RHS) title = "<bold>:: Upgrading plugins...<reset>" print(ansi_tran.sub(title)) for path in plug.keys(): info = "{}".format(plug[path]) a_spinner = spinner.Spinner(info, const.INTERVAL, const.SEQUENCE, const.OFFSET) local_dir = os.path.join(vimpckrc.pack_path, path) tmp_puller = git.Pull(local_dir) tmp_hasher = [git.Hash(local_dir) for i in range(2)] tmp_hasher[0].git_cmd() hash_bef = tmp_hasher[0].retrieve_stdout() a_spinner.start() out = tmp_puller.git_cmd() a_spinner.stop() tmp_hasher[1].git_cmd() hash_aft = tmp_hasher[1].retrieve_stdout() if out == 0: if hash_bef == hash_aft: message = "<yellow>Already up to date<reset>" else: message = "<green>Updated" status = "✓ {}: <green>{}<reset>".format(info, message) status = status.rjust(len(status) + const.OFFSET) status = ansi_tran.sub(status) print(status) else: status = "✗ {}: <red>Fail<reset>".format(info) status = status.rjust(len(status) + const.OFFSET) status = ansi_tran.sub(status) print(status) err_status = tmp_puller.error_proc.stderr.decode('UTF-8') # TODO: duplicate the retrieve_stdout method, merge them err_status = err_status.rjust(len(err_status) + const.OFFSET + 2) print(err_status) del a_spinner del tmp_puller del tmp_hasher