Exemple #1
0
 def _locate(self, *args, **kwargs):
     if not self._dont_update_db:
         try:
             with sh.contrib.sudo:
                 sh.updatedb()
                 self._dont_update_db = True
         except sh.ErrorReturnCode_1:
             print('Invalid password')
             exit(1)
     try:
         return [s.rstrip() for s in sh.locate(*args, **kwargs)]
     except sh.ErrorReturnCode_1:
         return []
Exemple #2
0
 def _locate(self, *args, **kwargs):
     if not self._dont_update_db:
         try:
             print(
                 'If you do not want to run sudo, use the following command to configure Phigaro:'
             )
             print('       phigaro-setup --no-updatedb')
             with sh.contrib.sudo:
                 sh.updatedb()
                 self._dont_update_db = True
         except sh.ErrorReturnCode_1:
             print('Invalid password')
             exit(1)
     try:
         return [s.rstrip() for s in sh.locate(*args, **kwargs)]
     except sh.ErrorReturnCode_1:
         return []
Exemple #3
0
def cli():
    global GLOBAL_MODE
    global CONFIG_DIR
    global TAG_LIST_CONFIG_PATH
    global SEARCH_PATTERN_CONFIG_PATH

    arguments = docopt(__doc__, version=__version__)

    GLOBAL_MODE = bool(arguments['--global'])

    if GLOBAL_MODE:
        if iswin():
            CONFIG_DIR = os.path.join(os.path.dirname(get_home_dir()),
                                      'All Users', '.jvirtualenv.d')
        else:
            CONFIG_DIR = '/etc/jvirtualenv.d'

    else:
        CONFIG_DIR = os.path.join(get_home_dir(), '.jvirtualenv.d')

    TAG_LIST_CONFIG_PATH = os.path.join(CONFIG_DIR, 'tag-list.json')
    SEARCH_PATTERN_CONFIG_PATH = os.path.join(CONFIG_DIR,
                                              'search-pattern.json')

    if arguments['list-tag']:
        pretty_print_config(get_config())

    elif arguments['reinit-tag']:
        if not iswin():
            with sh.contrib.sudo:
                sh.updatedb()

        init_config()
        color.print_ok('reinit config in %s' % TAG_LIST_CONFIG_PATH)

    elif arguments['--java']:
        version_info = find_version(arguments['--java'])
        if version_info is None:
            color.print_err('No matched tag')
            return

        project_path = arguments['<project>']
        write_activate_file(project_path, version_info['home'],
                            version_info['tag'], bool(arguments['--force']))