예제 #1
0
 def __init__(self, directory):
     """
     :param directory: Path to the repository folder
     :type directory: str
     """
     self.name = get_repository_name(directory)
     self.log = getLogger('leapp.repository').getChild(self.name)
     self._repo_dir = directory
     self._repo_id = get_repository_id(directory)
     self._repo_links = get_repository_links(directory)
     self._definitions = {}
     self.log.info("A new repository '%s' is initialized at %s", self.name, directory)
예제 #2
0
def pytest_collectstart(collector):
    if collector.nodeid:
        current_repo_basedir = find_repository_basedir(str(collector.fspath))
        if not current_repo_basedir:
            # This is not a repository
            return
        if not hasattr(collector.session, "leapp_repository"):
            collector.session.leapp_repository = RepositoryManager()
            collector.session.repo_base_dir = current_repo_basedir
            _load_and_add_repo(collector.session.leapp_repository,
                               current_repo_basedir)
        else:
            if not collector.session.leapp_repository.repo_by_id(
                    get_repository_id(current_repo_basedir)):
                _load_and_add_repo(collector.session.leapp_repository,
                                   current_repo_basedir)

        # we're forcing the actor context switch only when traversing new
        # actor
        if "/actors/" in str(collector.fspath) and (
                not hasattr(collector.session, "current_actor_path")
                or collector.session.current_actor_path + os.sep not in str(
                    collector.fspath)):
            actor = None
            for a in collector.session.leapp_repository.actors:
                if a.full_path == collector.fspath.dirpath().dirname:
                    actor = a
                    break

            if not actor:
                logger.info("No actor found, exiting collection...")
                return
            # we need to tear down the context from the previous
            # actor
            try:
                collector.session.current_actor_context.__exit__(
                    None, None, None)
            except AttributeError:
                pass
            else:
                logger.info(
                    "Actor %r context teardown complete",
                    collector.session.current_actor.name,
                )

            logger.info("Injecting actor context for %r", actor.name)
            collector.session.current_actor = actor
            collector.session.current_actor_context = actor.injected_context()
            collector.session.current_actor_context.__enter__()
            collector.session.current_actor_path = (
                collector.session.current_actor.full_path)
            logger.info("Actor %r context injected", actor.name)
예제 #3
0
def register_path(path):
    """
    Calling this function will register a path to be a well
    :param path: Path to the repository repository
    :return:
    """
    path = os.path.abspath(os.path.realpath(path))
    data = {}
    repos = get_user_config_repos()
    if os.path.isfile(repos):
        with open(repos) as f:
            data = json.load(f)
    data.setdefault('repos', {}).update({get_repository_id(path): path})
    with open(repos, 'w') as f:
        json.dump(data, f)
예제 #4
0
def list_repos(args):
    global_repos = {}
    if getattr(args, 'global', None) or args.all:
        global_repos = get_global_repositories_data()

    for entry in global_repos.values():
        print('{name:<35} [{uuid}] => {path}'.format(name=entry['name'],
                                                     path=entry['path'],
                                                     uuid=entry['id']))

    if not getattr(args, 'global', None):
        user_repos = get_user_config_repo_data()
        for path in user_repos.get('repos', {}).values():
            if os.path.isdir(path):
                name = get_repository_name(path)
                uuid = get_repository_id(path)
                print('{name:<35} [{uuid}] => {path}'.format(name=name,
                                                             path=path,
                                                             uuid=uuid))
예제 #5
0
def link_repo(args):
    if not any((args.path, args.name, args.uuid)):
        raise UsageError(
            'Please specify either --path, --name or --uuid to link another repository.'
        )
    data = get_user_config_repo_data()
    path = args.path
    if not path:
        if args.uuid:
            path = data.get('repos', {}).get(args.uuid, None)
        elif args.name:
            for repository_path in data.get('repos', {}).values():
                if os.path.isdir(repository_path):
                    if args.name == get_repository_name(repository_path):
                        path = repository_path
                        break
    if not path:
        raise UsageError(
            'Please specify a valid repository name, uuid or path')

    if add_repository_link('.', get_repository_id(path)):
        print('Added link to repository {path} - {name}'.format(
            path=path, name=get_repository_name(path)))