Пример #1
0
Файл: bat.py Проект: pct/vimpyre
 def bundles(self):
     """ List of bundles in the vimpyre path """
     try:
         with util.cd(self.VIMPYRE_PATH):
             return [item for item in listdir('.') if path.isdir(item)]
     except OSError:
         console('Cannot access your vimpyre path!')
Пример #2
0
 def bundles(self):
     """ List of bundles in the vimpyre path """
     try:
         with util.cd(self.VIMPYRE_PATH):
             return [item for item in listdir('.') if path.isdir(item)]
     except OSError:
         console('Cannot access your vimpyre path!')
Пример #3
0
def install(*scripts):
    """install scripts"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.install()
    else:
        console('Please use `vimpyre install <script-name>` and try again!')
Пример #4
0
def install(*scripts):
    """install scripts"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.install()
    else:
        console('Please use `vimpyre install <script-name>` and try again!')
Пример #5
0
def update(*scripts):
    """update scripts"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.update()
    else:
        console('Please use `vimpyre update <script-name>` and try again!')
Пример #6
0
def browse(*scripts):
    """browse script's homepage in your web browser"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.open_homepage()
    else:
        console('Please use `vimpyre browse <script-name>` and try again!')
Пример #7
0
def browse(*scripts):
    """browse script's homepage in your web browser"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.open_homepage()
    else:
        console('Please use `vimpyre browse <script-name>` and try again!')
Пример #8
0
def update(*scripts):
    """update scripts"""
    if len(scripts) >= 1:
        for index in range(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.update()
    else:
        console('Please use `vimpyre update <script-name>` and try again!')
Пример #9
0
 def open_homepage(self):
     console('=> => Send bats to open your browser...')
     bundle = self._check_name()
     if type(bundle) == dict and bundle['homepage']:
         webbrowser.open(bundle['homepage'])
     elif bundle:
         webbrowser.open(bundle)
     else:
         console('Sorry, no homepage found for this script.')
Пример #10
0
Файл: bat.py Проект: pct/vimpyre
 def open_homepage(self):
     console('=> => Send bats to open your browser...')
     bundle = self._check_name()
     if type(bundle) == dict and bundle['homepage']:
         webbrowser.open(bundle['homepage'])
     elif bundle:
         webbrowser.open(bundle)
     else:
         console('Sorry, no homepage found for this script.')
Пример #11
0
def dispatch(action, *scripts):
    """main function"""
    if action not in ACTIONS:
        console('no such action, exit!')
        sys.exit(1)

    if action not in NOARG_ACTIONS and not scripts:
        console('Please give a vim script name and try again!')
        sys.exit(1)
    elif action in NOARG_ACTIONS:
        eval(action + '()')
    else:
        scripts = '"' + '", "'.join(scripts) + '"'
        eval(action + '(%s)' % scripts)
Пример #12
0
def dispatch(action, *scripts):
    """main function"""
    if action not in ACTIONS:
        console('no such action, exit!')
        sys.exit(1)

    if action not in NOARG_ACTIONS and not scripts:
        console('Please give a vim script name and try again!')
        sys.exit(1)
    elif action in NOARG_ACTIONS:
        eval(action + '()')
    else:
        scripts = '"' + '", "'.join(scripts) + '"'
        eval(action + '(%s)' % scripts)
Пример #13
0
Файл: bat.py Проект: pct/vimpyre
    def install(self):
        console('=> => Send a bat to catch %s' % self.CURR_SCRIPT)

        try:
            ret = self._check_name()
            if ret:
                fetch_url = self._render_fetch_url(ret)
                cmd_fetch = 'git clone --depth 1 %s' % fetch_url
                util.mkdir_p(self.VIMPYRE_PATH)
                with util.cd(self.VIMPYRE_PATH):
                    system(cmd_fetch)
            else:
                msg = ('%s not found! Please use `vimpyre search <vim-script>`'
                       ' to check the script name and install again!' %
                       self.CURR_SCRIPT)
                console(msg)
        except:
            self.install_base()
Пример #14
0
    def install(self):
        console('=> => Send a bat to catch %s' % self.CURR_SCRIPT)

        try:
            ret = self._check_name()
            if ret:
                fetch_url = self._render_fetch_url(ret)
                cmd_fetch = 'git clone --depth 1 %s' % fetch_url
                util.mkdir_p(self.VIMPYRE_PATH)
                with util.cd(self.VIMPYRE_PATH):
                    system(cmd_fetch)
            else:
                msg = ('%s not found! Please use `vimpyre search <vim-script>`'
                       ' to check the script name and install again!' %
                       self.CURR_SCRIPT)
                console(msg)
        except:
            self.install_base()
Пример #15
0
Файл: bat.py Проект: pct/vimpyre
    def update_all(self):
        console('=> => Send bats to update all installed vim-scripts ...')
        if not self.bundles:
            console('No vim-scripts! Please use `vimpyre install <vim-scripts>` first!')
            sys.exit(1)

        for item in self.bundles:
            console('=> Update %s ...' % item)
            with util.cd(path.join(self.VIMPYRE_PATH, item)):
                system('git pull')
        console('Update all vim-scripts done!')
Пример #16
0
    def update_all(self):
        console('=> => Send bats to update all installed vim-scripts ...')
        if not self.bundles:
            console(
                'No vim-scripts! Please use `vimpyre install <vim-scripts>` first!'
            )
            sys.exit(1)

        for item in self.bundles:
            console('=> Update %s ...' % item)
            with util.cd(path.join(self.VIMPYRE_PATH, item)):
                system('git pull')
        console('Update all vim-scripts done!')
Пример #17
0
def search(*scripts):
    """search script"""
    if len(scripts) > 1:
        console('Please search one script name!')
        sys.exit(1)

    bat = Bat(scripts[0])
    rets = bat.search()

    console('=> => Send bats to search vim-scripts ...')
    if rets:
        for item in rets:
            if path.isdir(path.join(VIM_PATH, 'vimpyre', item['name'])):
                console('\033[1m%s\033[m => %s \033[1m[installed]\033[m' %
                        (item['name'], item['description']))
            else:
                console(
                    '\033[1m%s\033[m => %s | last: %s' %
                    (item['name'], item['description'], item['updated_at']))
    else:
        console('No such vim-scripts!')
Пример #18
0
Файл: bat.py Проект: pct/vimpyre
    def list_installed(self):
        console('=> => Send bats to collect all your vim-scripts')
        if not self.bundles:
            console('No vim-scripts found!')
            sys.exit(1)

        for bundle in self.bundles:
            bundle_path = path.join(self.VIMPYRE_PATH, bundle)
            with util.cd(bundle_path):
                if path.isfile(path.join('.git', 'config')):
                    url = subprocess.check_output(['grep', 'url', '.git/config']).decode("utf-8")
                    url = url.replace('\turl = ', '').replace('\n', '')
                    console('\033[1m%s\033[m => %s' % (bundle, url))
                else:
                    console('\033[0;31m%s\033[m => %s' % (bundle, 'No git repository!'))
Пример #19
0
Файл: bat.py Проект: pct/vimpyre
 def remove(self):
     console('=> => Send a bat to bite %s' % self.CURR_SCRIPT)
     bundle_path = path.join(self.VIMPYRE_PATH, self._filter_script_name())
     if path.isdir(bundle_path):
         shutil.rmtree(bundle_path)
         console('%s removed!' % self.CURR_SCRIPT)
     else:
         console('%s does not exist!' % self.CURR_SCRIPT)
Пример #20
0
 def remove(self):
     console('=> => Send a bat to bite %s' % self.CURR_SCRIPT)
     bundle_path = path.join(self.VIMPYRE_PATH, self._filter_script_name())
     if path.isdir(bundle_path):
         shutil.rmtree(bundle_path)
         console('%s removed!' % self.CURR_SCRIPT)
     else:
         console('%s does not exist!' % self.CURR_SCRIPT)
Пример #21
0
def search(*scripts):
    """search script"""
    if len(scripts) > 1:
        console('Please search one script name!')
        sys.exit(1)

    bat = Bat(scripts[0])
    rets = bat.search()

    console('=> => Send bats to search vim-scripts ...')
    if rets:
        for item in rets:
            if path.isdir(path.join(VIM_PATH, 'vimpyre', item['name'])):
                console('\033[1m%s\033[m => %s \033[1m[installed]\033[m' % (
                    item['name'],
                    item['description']))
            else:
                console('\033[1m%s\033[m => %s | last: %s' % (
                    item['name'],
                    item['description'],
                    item['updated_at']))
    else:
        console('No such vim-scripts!')
Пример #22
0
Файл: bat.py Проект: pct/vimpyre
 def update(self):
     console('=> => Send a bat to update %s' % self.CURR_SCRIPT)
     bundle_path = path.join(self.VIMPYRE_PATH, self._filter_script_name())
     if path.isdir(bundle_path):
         with util.cd(bundle_path):
             system('git pull')
         console('%s update done!' % self.CURR_SCRIPT)
     else:
         console('%s does not exist!' % self.CURR_SCRIPT)
Пример #23
0
 def update(self):
     console('=> => Send a bat to update %s' % self.CURR_SCRIPT)
     bundle_path = path.join(self.VIMPYRE_PATH, self._filter_script_name())
     if path.isdir(bundle_path):
         with util.cd(bundle_path):
             system('git pull')
         console('%s update done!' % self.CURR_SCRIPT)
     else:
         console('%s does not exist!' % self.CURR_SCRIPT)
Пример #24
0
    def list_installed(self):
        console('=> => Send bats to collect all your vim-scripts')
        if not self.bundles:
            console('No vim-scripts found!')
            sys.exit(1)

        for bundle in self.bundles:
            bundle_path = path.join(self.VIMPYRE_PATH, bundle)
            with util.cd(bundle_path):
                if path.isfile(path.join('.git', 'config')):
                    url = subprocess.check_output(
                        ['grep', 'url', '.git/config']).decode("utf-8")
                    url = url.replace('\turl = ', '').replace('\n', '')
                    console('\033[1m%s\033[m => %s' % (bundle, url))
                else:
                    console('\033[0;31m%s\033[m => %s' %
                            (bundle, 'No git repository!'))
Пример #25
0
Файл: bat.py Проект: pct/vimpyre
    def install_base(self):
        """
        Install pathogen.vim and create vimpyre directory.

            >>> bat = Bat()
            >>> bat.install_base()
            => => Send a bat to catch pathogen.vim ...
            Catch done! Please add the following message to your .vimrc:
            execute pathogen#infect('bundle/{}', 'vimpyre/{}')
        """
        try:
            console('=> => Send a bat to catch pathogen.vim ...')
            raw_urlopen = urllib.urlopen(self.pathogen_url)
            if raw_urlopen.getcode() == 200:
                util.mkdir_p(self.AUTOLOAD_PATH)
                util.mkdir_p(self.VIMPYRE_PATH)
                raw_pathogen = raw_urlopen.read()
                pathogen = path.join(self.AUTOLOAD_PATH, 'pathogen.vim')
                with open(pathogen, 'w') as f:
                    f.write(raw_pathogen)
                console('Catch done! Please add the following to your .vimrc:')
                console("execute pathogen#infect('bundle/{}', 'vimpyre/{}')")
            else:
                console('Pathogen vimscript not found in %s' % self.pathogen_url)
                console('You can change this url with enviroment variable VIM_PATHOGEN_URL')
                console('Catch fail! Please try again!')
        except:
            console('[Unexpected Error] Catch fail! Please try again!')
Пример #26
0
Файл: bat.py Проект: pct/vimpyre
 def remove_all(self):
     console('=> => Send bats to clean all vimpyre files')
     try:
         with util.cd(self.VIMPYRE_PATH):
             for bundle in self.bundles:
                 shutil.rmtree(bundle)
         console('Remove vimpyre bundles done!')
     except OSError:
         console('Could not remove bundles! Please verify permissions of '
                 'your bundle directories.')
     else:
         console('Please remove %s/pathogen.vim manually!' % self.AUTOLOAD_PATH)
         console('')
         console('If you wish to use vimpyre to manage your vim scripts again, you need to use `vimpyre init` first!')
Пример #27
0
 def remove_all(self):
     console('=> => Send bats to clean all vimpyre files')
     try:
         with util.cd(self.VIMPYRE_PATH):
             for bundle in self.bundles:
                 shutil.rmtree(bundle)
         console('Remove vimpyre bundles done!')
     except OSError:
         console('Could not remove bundles! Please verify permissions of '
                 'your bundle directories.')
     else:
         console('Please remove %s/pathogen.vim manually!' %
                 self.AUTOLOAD_PATH)
         console('')
         console(
             'If you wish to use vimpyre to manage your vim scripts again, you need to use `vimpyre init` first!'
         )
Пример #28
0
    def install_base(self):
        """
        Install pathogen.vim and create vimpyre directory.

            >>> bat = Bat()
            >>> bat.install_base()
            => => Send a bat to catch pathogen.vim ...
            Catch done! Please add the following message to your .vimrc:
            execute pathogen#infect('bundle/{}', 'vimpyre/{}')
        """
        try:
            console('=> => Send a bat to catch pathogen.vim ...')
            raw_urlopen = urllib.urlopen(self.pathogen_url)
            if raw_urlopen.getcode() == 200:
                util.mkdir_p(self.AUTOLOAD_PATH)
                util.mkdir_p(self.VIMPYRE_PATH)
                raw_pathogen = raw_urlopen.read()
                pathogen = path.join(self.AUTOLOAD_PATH, 'pathogen.vim')
                with open(pathogen, 'w') as f:
                    f.write(raw_pathogen)
                console('Catch done! Please add the following to your .vimrc:')
                console("execute pathogen#infect('bundle/{}', 'vimpyre/{}')")
            else:
                console('Pathogen vimscript not found in %s' %
                        self.pathogen_url)
                console(
                    'You can change this url with enviroment variable VIM_PATHOGEN_URL'
                )
                console('Catch fail! Please try again!')
        except:
            console('[Unexpected Error] Catch fail! Please try again!')