Esempio n. 1
0
 def init_svn_repo(self, subpath, files=None, repo_url=None):
     if not repo_url:
         repo_url = create_remote_svn_repo(temp_folder())
     _, rev = create_local_svn_checkout(files,
                                        repo_url,
                                        folder=self.current_folder,
                                        rel_project_path=subpath,
                                        delete_checkout=False)
     return rev
Esempio n. 2
0
    def __init__(self,
                 base_path=None,
                 read_permissions=None,
                 write_permissions=None,
                 users=None,
                 base_url=None,
                 plugins=None,
                 server_capabilities=None):

        plugins = plugins or []
        if not base_path:
            base_path = temp_folder()

        if not os.path.exists(base_path):
            raise Exception("Base path not exist! %s")

        self._base_path = base_path

        server_config = migrate_and_get_server_config(base_path)
        if server_capabilities is None:
            server_capabilities = set(SERVER_CAPABILITIES)

        # Encode and Decode signature for Upload and Download service
        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)
        base_url = base_url or server_config.public_url
        self.server_store = get_server_store(server_config.disk_storage_path,
                                             base_url, updown_auth_manager)

        # Prepare some test users
        if not read_permissions:
            read_permissions = server_config.read_permissions
            read_permissions.append(
                ("private_library/1.0.0@private_user/testing", "*"))
            read_permissions.append(("*/*@*/*", "*"))

        if not write_permissions:
            write_permissions = server_config.write_permissions

        if not users:
            users = dict(server_config.users)

        users[TESTING_REMOTE_PRIVATE_USER] = TESTING_REMOTE_PRIVATE_PASS

        authorizer = BasicAuthorizer(read_permissions, write_permissions)
        authenticator = BasicAuthenticator(users)
        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        self.port = server_config.port
        self.ra = ConanServer(self.port, credentials_manager,
                              updown_auth_manager, authorizer, authenticator,
                              self.server_store, server_capabilities)
        for plugin in plugins:
            self.ra.api_v1.install(plugin)
            self.ra.api_v2.install(plugin)
Esempio n. 3
0
def _copy_cache_folder(target_folder):
    # Some variables affect to cache population (take a different default folder)
    vars = [CONAN_V2_MODE_ENVVAR, 'CC', 'CXX', 'PATH']
    cache_key = hash('|'.join(
        map(str, [os.environ.get(it, None) for it in vars])))
    master_folder = _copy_cache_folder.master.setdefault(
        cache_key, temp_folder(create_dir=False))
    if not os.path.exists(master_folder):
        # Create and populate the cache folder with the defaults
        cache = ClientCache(master_folder, TestBufferConanOutput())
        cache.initialize_config()
        cache.registry.initialize_remotes()
        cache.initialize_default_profile()
        cache.initialize_settings()
    shutil.copytree(master_folder, target_folder)
Esempio n. 4
0
def create_local_svn_checkout(files,
                              repo_url,
                              rel_project_path=None,
                              commit_msg='default commit message',
                              delete_checkout=True,
                              folder=None):
    tmp_dir = folder or temp_folder()
    try:
        rel_project_path = rel_project_path or str(uuid.uuid4())
        # Do not use SVN class as it is what we will be testing
        subprocess.check_output('svn co "{url}" "{path}"'.format(url=repo_url,
                                                                 path=tmp_dir),
                                shell=True)
        tmp_project_dir = os.path.join(tmp_dir, rel_project_path)
        mkdir(tmp_project_dir)
        save_files(tmp_project_dir, files)
        with chdir(tmp_project_dir):
            subprocess.check_output("svn add .", shell=True)
            subprocess.check_output('svn commit -m "{}"'.format(commit_msg),
                                    shell=True)
            if SVN.get_version() >= SVN.API_CHANGE_VERSION:
                rev = check_output_runner(
                    "svn info --show-item revision").strip()
            else:
                import xml.etree.ElementTree as ET
                output = check_output_runner("svn info --xml").strip()
                root = ET.fromstring(output)
                rev = root.findall("./entry")[0].get("revision")
        project_url = repo_url + "/" + quote(
            rel_project_path.replace("\\", "/"))
        return project_url, rev
    finally:
        if delete_checkout:
            shutil.rmtree(tmp_dir,
                          ignore_errors=False,
                          onerror=try_remove_readonly)
Esempio n. 5
0
def create_local_git_repo(files=None,
                          branch=None,
                          submodules=None,
                          folder=None,
                          commits=1,
                          tags=None,
                          origin_url=None):
    tmp = folder or temp_folder()
    tmp = get_cased_path(tmp)
    if files:
        save_files(tmp, files)
    git = Git(tmp)
    git.run("init .")
    git.run('config user.email "*****@*****.**"')
    git.run('config user.name "Your Name"')

    if branch:
        git.run("checkout -b %s" % branch)

    git.run("add .")
    for i in range(0, commits):
        git.run('commit --allow-empty -m "commiting"')

    tags = tags or []
    for tag in tags:
        git.run("tag %s" % tag)

    if submodules:
        for submodule in submodules:
            git.run('submodule add "%s"' % submodule)
        git.run('commit -m "add submodules"')

    if origin_url:
        git.run('remote add origin {}'.format(origin_url))

    return tmp.replace("\\", "/"), git.get_revision()
Esempio n. 6
0
def create_remote_svn_repo(folder=None):
    tmp_dir = folder or temp_folder()
    subprocess.check_output('svnadmin create "{}"'.format(tmp_dir), shell=True)
    return SVN.file_protocol + quote(tmp_dir.replace("\\", "/"), safe='/:')
Esempio n. 7
0
 def __init__(self, *args, **kwargs):
     _base_dir = temp_folder()
     self.default_profile_path = os.path.join(_base_dir, "default")
     self.profiles_path = _base_dir
Esempio n. 8
0
    def __init__(self,
                 cache_folder=None,
                 current_folder=None,
                 servers=None,
                 users=None,
                 requester_class=None,
                 runner=None,
                 path_with_spaces=True,
                 revisions_enabled=None,
                 cpu_count=1,
                 default_server_user=None,
                 cache_autopopulate=True):
        """
        current_folder: Current execution folder
        servers: dict of {remote_name: TestServer}
        logins is a list of (user, password) for auto input in order
        if required==> [("lasote", "mypass"), ("other", "otherpass")]
        """
        if default_server_user is not None:
            if servers is not None:
                raise Exception(
                    "Cannot define both 'servers' and 'default_server_user'")
            if users is not None:
                raise Exception(
                    "Cannot define both 'users' and 'default_server_user'")
            if default_server_user is True:
                server_users = {"user": "******"}
                users = {"default": [("user", "password")]}
            else:
                server_users = default_server_user
                users = {"default": list(default_server_user.items())}
            # Allow write permissions to users
            server = TestServer(users=server_users,
                                write_permissions=[("*/*@*/*", "*")])
            servers = {"default": server}

        self.users = users
        if self.users is None:
            self.users = {
                "default":
                [(TESTING_REMOTE_PRIVATE_USER, TESTING_REMOTE_PRIVATE_PASS)]
            }

        if cache_autopopulate and (not cache_folder
                                   or not os.path.exists(cache_folder)):
            # Copy a cache folder already populated
            self.cache_folder = cache_folder or temp_folder(path_with_spaces,
                                                            create_dir=False)
            _copy_cache_folder(self.cache_folder)
        else:
            self.cache_folder = cache_folder or temp_folder(path_with_spaces)

        self.requester_class = requester_class
        self.runner = runner

        if servers and len(servers) > 1 and not isinstance(
                servers, OrderedDict):
            raise Exception(
                textwrap.dedent("""
                Testing framework error: Servers should be an OrderedDict. e.g:
                    servers = OrderedDict()
                    servers["r1"] = server
                    servers["r2"] = TestServer()
            """))

        self.servers = servers or {}
        if servers is not False:  # Do not mess with registry remotes
            self.update_servers()
        self.current_folder = current_folder or temp_folder(path_with_spaces)

        # Once the client is ready, modify the configuration
        mkdir(self.current_folder)
        self.tune_conan_conf(cache_folder, cpu_count, revisions_enabled)