Ejemplo n.º 1
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!')
Ejemplo n.º 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!')
Ejemplo n.º 3
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:
            call pathogen#runtime_append_all_bundles("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('call pathogen#runtime_append_all_bundles("vimpyre")')
            else:
                console('Catch fail! Please try again!')
        except:
            console('[Unexpected Error] Catch fail! Please try again!')
Ejemplo n.º 4
0
def update(*scripts):
    """update scripts"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.update()
    else:
        console('Please use `vimpyre update <script-name>` and try again!')
Ejemplo n.º 5
0
def install(*scripts):
    """install scripts"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.install()
    else:
        console('Please use `vimpyre install <script-name>` and try again!')
Ejemplo n.º 6
0
def browse(*scripts):
    """browse script's homepage in your web browser"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.open_homepage()
    else:
        console('Please use `vimpyre browse <script-name>` and try again!')
Ejemplo n.º 7
0
def browse(*scripts):
    """browse script's homepage in your web browser"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.open_homepage()
    else:
        console('Please use `vimpyre browse <script-name>` and try again!')
Ejemplo n.º 8
0
def install(*scripts):
    """install scripts"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.install()
    else:
        console('Please use `vimpyre install <script-name>` and try again!')
Ejemplo n.º 9
0
def update(*scripts):
    """update scripts"""
    if len(scripts) >= 1:
        for index in xrange(0, len(scripts)):
            bat = Bat(scripts[index])
            bat.update()
    else:
        console('Please use `vimpyre update <script-name>` and try again!')
Ejemplo n.º 10
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.')
Ejemplo n.º 11
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.')
Ejemplo n.º 12
0
 def doremove(self, args):
     """remove scripts"""
     scripts = args.scripts
     if len(scripts) >= 1:
         for index in xrange(0, len(scripts)):
             bat = Bat(scripts[index])
             bat.remove()
     else:
         console('Please use `vimpyre remove <script-name>` and try again!')
Ejemplo n.º 13
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
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'].encode('utf-8'), item['description'].encode('utf-8')))
            else:
                console('\033[1m%s\033[m => %s' % (item['name'].encode('utf-8'), item['description'].encode('utf-8')))
    else:
        console('No such vim-scripts!')
Ejemplo n.º 16
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()
Ejemplo n.º 17
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()
Ejemplo n.º 18
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!')
Ejemplo n.º 19
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!')
Ejemplo n.º 20
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']).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!'))
Ejemplo n.º 21
0
    def dosearch(self, args):
        """search script"""
        bat = Bat(args.script)
        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'].encode('utf-8'), item['description'].encode('utf-8')))
                else:
                    console('\033[1m%s\033[m => %s' % (item['name'].encode('utf-8'), item['description'].encode('utf-8')))
        else:
            console('No such vim-scripts!')
Ejemplo n.º 22
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'].encode('utf-8'),
                         item['description'].encode('utf-8')))
            else:
                console('\033[1m%s\033[m => %s' %
                        (item['name'].encode('utf-8'),
                         item['description'].encode('utf-8')))
    else:
        console('No such vim-scripts!')
Ejemplo n.º 23
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)
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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):
                url = subprocess.check_output(['grep', 'url', '.git/config']).replace('\turl = ', '').replace('\n', '')
                console('\033[1m%s\033[m => %s' % (bundle, url))
Ejemplo n.º 28
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!')
Ejemplo n.º 29
0
def trace(text1, text2=""):
    if (constants.show_trace):
        util.console(text1, text2)
Ejemplo n.º 30
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 and clean `call pathogen#runtime_append_all_bundles("vimpyre")` from your .vimrc!' % self.AUTOLOAD_PATH)
         console('')
         console('If you wish to use vimpyre to manage your vim scripts again, you need to use `vimpyre init` first!')
Ejemplo n.º 31
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!')
Ejemplo n.º 32
0
 def trace(self, text1, text2=""):
     if (self.show_trace):
         util.console(text1, text2)
Ejemplo n.º 33
0
    def debug(self):
        util.console(" ------------------- debug -------------------")
        util.console(" v_RM: ", self.v_RM)
        util.console(" v_D: ", self.v_D)
        util.console(" v_MS: ", self.v_MS)
        util.console(" v_QSi: ", self.v_QSi)
        util.console(" v_VSi: ", self.v_VSi)
        util.console(" v_WSi: ", self.v_WSi)
        util.console(" v_VB: ", self.v_VB)
        util.console(" v_OB: ", self.v_OB)
        util.console(" v_V: ", self.v_V)
        util.console(" v_G: ", self.v_G)
        util.console(" v_W: ", self.v_W)

        util.console_list(" v_L: ", self.v_L)
        util.console_list(" v_C: ", self.v_C)
        util.console_list(" v_F: ", self.v_F)
        util.console(" ------------------- debug -------------------")