Ejemplo n.º 1
0
 def run(cls, **kwargs):
     if kwargs['simple']:
         for pkg in sorted(dapicli.get_installed_daps()):
             print(pkg)
     else:
         for pkg, instances in sorted(dapicli.get_installed_daps_detailed().items()):
             versions = []
             for instance in instances:
                 location = utils.unexpanduser(instance['location'])
                 version = instance['version']
                 if not versions:  # if this is the first
                     version = utils.bold(version)
                 versions.append('{v}:{p}'.format(v=version, p=location))
             pkg = utils.bold(pkg)
             print('{pkg} ({versions})'.format(pkg=pkg, versions=' '.join(versions)))
Ejemplo n.º 2
0
def print_installed_dap_list(simple=False):
    '''Prints all installed DAPs in a human readable form to stdout'''
    if simple:
        for pkg in sorted(get_installed_daps()):
            print(pkg)
    else:
        for pkg, instances in sorted(get_installed_daps_detailed().items()):
            versions = []
            for instance in instances:
                location = utils.unexpanduser(instance['location'])
                version = instance['version']
                if not versions:  # if this is the first
                    version = utils.bold(version)
                versions.append('{v}:{p}'.format(v=version, p=location))
            pkg = utils.bold(pkg)
            print('{pkg} ({versions})'.format(pkg=pkg, versions=' '.join(versions)))
Ejemplo n.º 3
0
def format_installed_dap_list(simple=False):
    '''Formats all installed DAPs in a human readable form to list of lines'''
    lines = []
    if simple:
        for pkg in sorted(get_installed_daps()):
            lines.append(pkg)
    else:
        for pkg, instances in sorted(get_installed_daps_detailed().items()):
            versions = []
            for instance in instances:
                location = utils.unexpanduser(instance['location'])
                version = instance['version']
                if not versions:  # if this is the first
                    version = utils.bold(version)
                versions.append('{v}:{p}'.format(v=version, p=location))
            pkg = utils.bold(pkg)
            lines.append('{pkg} ({versions})'.format(
                pkg=pkg, versions=' '.join(versions)))
    return lines
Ejemplo n.º 4
0
def uninstall_dap(name, confirm=False, allpaths=False):
    if allpaths:
        location = None
        hint = 'DEVASSISTANT_PATH'
    else:
        location = _install_path()
        hint = utils.unexpanduser(_install_path())
    if name not in get_installed_daps(location=location):
        raise Exception(
            'Cannot uninstall DAP {dap}, it is not in {path}'.
            format(dap=name, path=hint))
    ret = []

    # We need to remove all the daps depending on this one
    for dap in get_installed_daps(location=location, skip_distro=True):
        deps = _get_dependencies_of(dap, location=location)
        if deps:
            deps = [_strip_version_from_dependency(dep) for dep in deps]
            if name in deps:
                # This dap might have been removed when removing other dap(s) in this loop
                if dap in get_installed_daps(location=location, skip_distro=True):
                    ret += uninstall_dap(dap, confirm=confirm, allpaths=allpaths)

    if allpaths:
        locations = _data_dirs()
    else:
        locations = [_install_path()]

    for location in locations:
        if name not in get_installed_daps(location=location):
            continue
        if location == DISTRO_DIRECTORY:
            logger.warn(
                'Skipping {d} in {l}, as it is protected. See docs for explanation.'.format(
                    d=name, l=DISTRO_DIRECTORY))
            continue

        g = ['{d}/meta/{dap}.yaml'.format(d=location, dap=name)]
        for loc in 'assistants files icons'.split():
            g += glob.glob('{d}/{loc}/*/{dap}.*'.format(d=location, loc=loc, dap=name))
            g += glob.glob('{d}/{loc}/*/{dap}'.format(d=location, loc=loc, dap=name))
        for loc in 'snippets doc'.split():
            g += glob.glob('{d}/{loc}/{dap}.yaml'.format(d=location, loc=loc, dap=name))
            g += glob.glob('{d}/{loc}/{dap}'.format(d=location, loc=loc, dap=name))

        if confirm:
            print('DAP {name} and the following files and directories will be removed:'.
                  format(name=name))
            for f in g:
                print('    ' + utils.unexpanduser(f))
            inp = raw_input if not six.PY3 else input
            ok = inp('Is that OK? [y/N] ')
            if ok.lower() != 'y':
                raise Exception('Stopped by user')

        for f in g:
            try:
                os.remove(f)
            except OSError as e:
                if e.errno == errno.EISDIR:  # Is a directory
                    shutil.rmtree(f)
                elif e.errno == errno.EACCES:  # Permission denied
                    raise Exception(
                        'Permission denied, you might want to run this command as root')
                else:
                    raise(e)
        ret += [name]
    return ret
Ejemplo n.º 5
0
def uninstall_dap(name, confirm=False, allpaths=False, __ui__=''):
    if allpaths:
        location = None
        hint = 'DEVASSISTANT_PATH'
    else:
        location = _install_path()
        hint = utils.unexpanduser(_install_path())
    if name not in get_installed_daps(location=location):
        raise DapiLocalError(
            'Cannot uninstall DAP {d}, it is not in {p}'.format(d=name,
                                                                p=hint))
    ret = []

    # We need to remove all the daps depending on this one
    for dap in get_installed_daps(location=location, skip_distro=True):
        deps = _get_dependencies_of(dap, location=location)
        if deps:
            deps = [_strip_version_from_dependency(dep) for dep in deps]
            if name in deps:
                # This dap might have been removed when removing other dap(s) in this loop
                if dap in get_installed_daps(location=location,
                                             skip_distro=True):
                    ret += uninstall_dap(dap,
                                         confirm=confirm,
                                         allpaths=allpaths,
                                         __ui__=__ui__)

    if allpaths:
        locations = _data_dirs()
    else:
        locations = [_install_path()]

    for location in locations:
        if name not in get_installed_daps(location=location):
            continue
        if location == DISTRO_DIRECTORY:
            logger.warn(
                'Skipping {d} in {l}, as it is protected. See docs for explanation.'
                .format(d=name, l=DISTRO_DIRECTORY))
            continue

        g = ['{d}/meta/{dap}.yaml'.format(d=location, dap=name)]
        for loc in 'assistants files icons'.split():
            g += glob.glob('{d}/{loc}/*/{dap}.*'.format(d=location,
                                                        loc=loc,
                                                        dap=name))
            g += glob.glob('{d}/{loc}/*/{dap}'.format(d=location,
                                                      loc=loc,
                                                      dap=name))
        for loc in 'snippets doc'.split():
            g += glob.glob('{d}/{loc}/{dap}.yaml'.format(d=location,
                                                         loc=loc,
                                                         dap=name))
            g += glob.glob('{d}/{loc}/{dap}'.format(d=location,
                                                    loc=loc,
                                                    dap=name))

        if confirm:
            msg = 'DAP {name} and the following files and directories will be removed:\n'
            msg = msg.format(name=name)
            for f in g:
                msg += '    ' + utils.unexpanduser(f) + '\n'

            comm = {'message': msg, 'prompt': 'Is that OK?'}
            command = lang.Command(comm=comm,
                                   comm_type='ask_confirm',
                                   kwargs={'__ui__': __ui__})
            answer = command.run()[0]
            if not answer:
                raise DapiLocalError('Stopped by user')
        for f in g:
            try:
                os.remove(f)
            except OSError as e:
                if e.errno == errno.EISDIR:  # Is a directory
                    shutil.rmtree(f)
                elif e.errno == errno.EACCES:  # Permission denied
                    raise DapiLocalError(
                        'Permission denied, you might want to run this command as root'
                    )
                else:
                    raise (e)
        ret += [name]
    return ret
Ejemplo n.º 6
0
def uninstall_dap(name, confirm=False, allpaths=False, __ui__=''):
    if allpaths:
        location = None
        hint = 'DEVASSISTANT_PATH'
    else:
        location = _install_path()
        hint = utils.unexpanduser(_install_path())
    if name not in get_installed_daps(location=location):
        raise DapiLocalError('Cannot uninstall DAP {d}, it is not in {p}'.format(d=name, p=hint))
    ret = []

    # We need to remove all the daps depending on this one
    for dap in get_installed_daps(location=location, skip_distro=True):
        deps = _get_dependencies_of(dap, location=location)
        if deps:
            deps = [_strip_version_from_dependency(dep) for dep in deps]
            if name in deps:
                # This dap might have been removed when removing other dap(s) in this loop
                if dap in get_installed_daps(location=location, skip_distro=True):
                    ret += uninstall_dap(dap, confirm=confirm, allpaths=allpaths, __ui__=__ui__)

    if allpaths:
        locations = _data_dirs()
    else:
        locations = [_install_path()]

    for location in locations:
        if name not in get_installed_daps(location=location):
            continue
        if location == DISTRO_DIRECTORY:
            logger.warn(
                'Skipping {d} in {l}, as it is protected. See docs for explanation.'.format(
                    d=name, l=DISTRO_DIRECTORY))
            continue

        g = ['{d}/meta/{dap}.yaml'.format(d=location, dap=name)]
        for loc in 'assistants files icons'.split():
            g += glob.glob('{d}/{loc}/*/{dap}.*'.format(d=location, loc=loc, dap=name))
            g += glob.glob('{d}/{loc}/*/{dap}'.format(d=location, loc=loc, dap=name))
        for loc in 'snippets doc'.split():
            g += glob.glob('{d}/{loc}/{dap}.yaml'.format(d=location, loc=loc, dap=name))
            g += glob.glob('{d}/{loc}/{dap}'.format(d=location, loc=loc, dap=name))

        if confirm:
            msg = 'DAP {name} and the following files and directories will be removed:\n'
            msg = msg.format(name=name)
            for f in g:
                msg += '    ' + utils.unexpanduser(f) + '\n'

            comm = {'message': msg, 'prompt': 'Is that OK?'}
            command = lang.Command(comm=comm, comm_type='ask_confirm', kwargs={'__ui__': __ui__})
            answer = command.run()[0]
            if not answer:
                raise DapiLocalError('Stopped by user')
        for f in g:
            try:
                os.remove(f)
            except OSError as e:
                if e.errno == errno.EISDIR:  # Is a directory
                    shutil.rmtree(f)
                elif e.errno == errno.EACCES:  # Permission denied
                    raise DapiLocalError(
                        'Permission denied, you might want to run this command as root')
                else:
                    raise(e)
        ret += [name]
    return ret