当前位置: 首页>>代码示例>>Python>>正文


Python Gittle.clone方法代码示例

本文整理汇总了Python中gittle.Gittle.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Gittle.clone方法的具体用法?Python Gittle.clone怎么用?Python Gittle.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gittle.Gittle的用法示例。


在下文中一共展示了Gittle.clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_repo

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
    def read_repo(self, git=None, ls=None):
        clone_path = path.join(self.dir_base, str(uuid.uuid4()) if git is not None else 'upstream')

        print('github url', git if git is not None else self.upstream)

        git_url = urlparse(git if git is not None else self.upstream)
        clone_url = None
        splitted_path = git_url.path.strip('/').split('/')

        if len(splitted_path) > 2:
            clone_url = git_url.scheme + '://' + git_url.netloc + '/' + splitted_path[0] + '/' + splitted_path[1] + '.git'
        else:
            clone_url = git if git is not None else self.upstream

        print('clone url', clone_url)

        # cloning the repository
        Gittle.clone(clone_url, clone_path)

        if len(splitted_path) > 2:
            readme_file = self.find_readme(clone_path, '/'.join(str(x) for x in splitted_path[2:]))
        else:
            readme_file = self.find_readme(clone_path)

        print(clone_url, readme_file)

        try:
            with open(path.join(clone_path, readme_file)) as f:
                soup = BeautifulSoup(mistune.markdown(f.read()), 'html.parser')

                self.save_md(soup, True if git is None else False, ls)

            self.stdout.write(self.style.SUCCESS('Successfully read the upstream'))
        except Exception as exp:
            print('An error happened while reading the repo.', exp)
开发者ID:usablica,项目名称:lsawesome,代码行数:37,代码来源:crawler.py

示例2: __init__

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
 def __init__(self, uri, branch="master", project_name="project",
                  specific_sha=None, threshold=False, correction=False):
     self._data_frame = None
     self.files = {}
     self.project_name = project_name
     self.git_repository = uri
     git_url = re.compile(GIT_URL)
     _uri_safe = ''.join([c for c in uri if c.isalnum()])
     self.repo_path = os.path.join(TMP_DIR, _uri_safe)
     self.__tmp_repository = self.repo_path
     self.index_sha = 0
     self.size = 0
     self.__first = True
     self.__spec_file = []
     self.specific_sha = specific_sha
     if os.path.exists(self.repo_path):
         #dont use cached repo
         shutil.rmtree(self.repo_path)
     if os.path.exists("diff_{0}.txt".format(self.project_name)):
         os.remove("diff_{0}.txt".format(self.project_name))
     is_url = git_url.search(uri)
     if is_url is None:
         self.__repository = Gittle(self.git_repository)
         self.__tmp_repository = self.git_repository
     else:
         if self.git_repository.find(".git") < 0:
             LOGGER.info(r"Must end .git i will add manualy")
             self.git_repository += ".git"
         try:
             LOGGER.info(r'Cloning git repo: {0}'.format(self.repo_path))
             Gittle.clone(self.git_repository, self.__tmp_repository)
         except InvalidRemoteUrl as err:
             raise Exception(r"Could not clone repository! Is not url."
                 " Error: {0}".format(err))
         except ValueError as err:
             raise Exception(r"Is not url."
                 " Error: {0}".format(err))
         except KeyError as err:
             raise Exception(r"Could not clone repository."
                 " Error: {0}".format(err))
         except RefFormatError:
             n_path = "/tmp/{0}".format(_uri_safe)
             if os.path.exists(n_path):
                 #dont use cached repo
                 shutil.rmtree(n_path)
             if branch is None:
                 os.system("git clone {0} {1} 2>&1".format(uri, n_path))
             else:
                 os.system("git clone -b {0} {1} {2} 2>&1"
                                 .format(branch, uri, n_path))
             self.__tmp_repository = n_path
         self.__repository = Gittle(self.__tmp_repository, origin_uri=uri)
         self.__repository.DEFAULT_BRANCH = branch
     if branch not in self.__repository.branches:
         LOGGER.error("Branch {0} is no in {1}".format(branch, uri))
         raise Exception("Branch {0} is no in {1}".format(branch, uri))
     self.__fill_data(branch, specific_sha)
     self.eval_commit_to_future(threshold, correction)
开发者ID:Radymus,项目名称:QMetric,代码行数:60,代码来源:QMetric.py

示例3: clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
    def clone(repo_info):
        repo_context = None
        try:
            repo_context = AgentGitHandler.create_git_repo_context(repo_info)
            #create the directory if it doesn't exist
            if not os.path.isdir(repo_context.local_repo_path):
                cartridgeagentutils.create_dir(repo_context.local_repo_path)

            auth = AgentGitHandler.create_auth_configuration(repo_context)

            if auth is not None:
                # authentication is required, use Gittle
                gittle_repo = Gittle.clone(repo_context.repo_url, repo_context.local_repo_path, auth=auth)
                repo = Repo(repo_context.local_repo_path)
            else:
                # authentication is not required, use GitPython
                repo = Repo.clone_from(repo_context.repo_url, repo_context.local_repo_path)
                gittle_repo = Gittle(repo_context.local_repo_path)

            repo_context.cloned = True
            repo_context.gittle_repo = gittle_repo
            repo_context.repo  = repo
            AgentGitHandler.add_repo_context(repo_context)
            AgentGitHandler.log.info("Git clone operation for tenant %r successful" % repo_context.tenant_id)
        except urllib2.URLError:
            AgentGitHandler.log.exception("Accessing remote git repository failed for tenant %r" % repo_context.tenant_id)
        except OSError:
            AgentGitHandler.log.exception("Permission denied for repository path for tenant %r" % repo_context.tenant_id)
        except:
            AgentGitHandler.log.exception("Git clone operation for tenant %r failed" % repo_context.tenant_id)
        finally:
            return repo_context
开发者ID:kasundsilva,项目名称:stratos,代码行数:34,代码来源:agentgithandler.py

示例4: get_readme

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def get_readme(project):
    """
    This function tries to get the content of the readme file. If it does, then
    it updates the description with the content of the latest readme. It runs
    every time a project is saved, on post save hook.
    """
    repos = project.repository_set.all()
    if repos:
        for repository in repos:
            if repository.url:
                path = ("/tmp/%s/") % "".join(random.choice(string.lowercase) for i in range(20))
                try:
                    repo = Gittle.clone(repository.url, path, bare=True)
                except:
                    # We use update, because we want to bypass
                    # the post_save function.
                    from index.models import Project

                    Project.objects.filter(id=project.id).update(public=False)
                    pass
                else:
                    readme = repo.file_versions("README.md")
                    if readme:
                        readme = readme[0].get("data")
                        # We use update, because we want to bypass
                        # the post_save function.
                        from index.models import Project

                        Project.objects.filter(id=project.id).update(description=readme)
                        shutil.rmtree(repo.path)
                        return True
    return False
开发者ID:pombredanne,项目名称:project_index,代码行数:34,代码来源:tasks.py

示例5: get_requirements

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def get_requirements(project):
    """
    This function tries to get the content of the requirements file.
    If it does, then it updates the requirements. In case we cant access the
    repository we will try to see if the user has uploaded a requirements.txt
    by himself.
    It runs every time a project is saved, on post save hook.
    """
    repos = project.repository_set.all()
    if repos:
        for repository in repos:
            if repository.url:
                path = ("/tmp/%s/") % "".join([random.choice(string.lowercase) for i in range(20)])
                try:
                    repo = Gittle.clone(repository.url, path, bare=True)
                except:
                    # We use update, because we want to bypass
                    # the post_save function.
                    from index.models import Project

                    Project.objects.filter(id=project.id).update(public=False)
                else:
                    requirements = repo.file_versions("requirements.txt")
                    if requirements:
                        requirements = requirements[0].get("data")
                        for r in requirements.split("\n"):
                            parse_dependencies(r, project)
                        shutil.rmtree(repo.path)
                        return True
    if project.dependency_file:
        if os.path.isfile(project.dependency_file.path):
            for l in project.dependency_file.readlines():
                parse_dependencies(l, project)
            return True
    return False
开发者ID:pombredanne,项目名称:project_index,代码行数:37,代码来源:tasks.py

示例6: git_clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def git_clone(args):
    if len(args) > 0:
           url = args[0]
           repo = Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)

           #Set the origin
           config = repo.repo.get_config()
           config.set(('remote','origin'),'url',url)
           config.write_to_path()
          
    else:
        print command_help['clone']
开发者ID:RichardPotthoff,项目名称:stash,代码行数:14,代码来源:git.py

示例7: git_clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def git_clone(args):
    if len(args) > 0:
           url = args[0]
           repo = Gittle.clone(args[0], args[1] if len(args)>1 else os.path.split(args[0])[-1].rstrip('.git'), bare=False)

           #Set the origin
           config = repo.repo.get_config()
           config.set(('remote','origin'),'url',url)
           config.write_to_path()
          
    else:
        print(command_help['clone'])
开发者ID:BBOOXX,项目名称:stash,代码行数:14,代码来源:git.py

示例8: __init__

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
 def __init__(self,git_path,rskey= None,logger=dg):
     self.User = {}
     self.Commits = {}
     self.__logger = logger
     self.__tmp_repository = "/tmp/temporary_git_repository"
     if(os.path.exists(self.__tmp_repository)):
         self.__tmp_repository = self.__tmp_repository+"_"+datetime.datetime.now().isoformat()
 
     print git_path
     try:
         Gittle.clone(git_path,self.__tmp_repository)
     except:
         pass
         #self.__logger("Error could not clone repository.")
         #return
     self.__repository = Gittle(self.__tmp_repository)
     if rskey != None:
         key_file = open(rskey)
         self.__repository.auth(pkey=key_file)        
     #print self.__tmp_repository
     self.fill_User()
开发者ID:kejbaly2,项目名称:SWMetric,代码行数:23,代码来源:GitStat.py

示例9: git_clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def git_clone(args):
    if len(args) > 0:
        url = args[0]

        repo = Gittle.clone(args[0], args[1] if len(args) > 1 else ".", bare=False)

        # Set the origin
        config = repo.repo.get_config()
        config.set(("remote", "origin"), "url", url)
        config.write_to_path()
    else:
        print command_help["clone"]
开发者ID:miwagner1,项目名称:Pythonista,代码行数:14,代码来源:git.py

示例10: update_repo

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def update_repo(cookie):
    # TODO: add commit info to the CookieCutter model
    if not os.path.isdir(cookie.repo_path):
        repo = Gittle.clone(cookie.url, cookie.repo_path)
    else:
        repo = Gittle(cookie.repo_path, cookie.url)
        repo.pull()

    cookie.options = {'repo_name': 'your repo'}
    options_file = os.path.join(cookie.repo_path, 'cookiecutter.json')

    if os.path.isfile(options_file):
        cookie.options.update(json.load(open(options_file)))

    cookie.save()
开发者ID:DjangoLover,项目名称:ROLL-studio,代码行数:17,代码来源:tasks.py

示例11: git_clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
		def git_clone(args):
			if len(args) > 0:
				url = args[0]

				#def clone(source, target=None, bare=False, checkout=None, config=None, opener=None, outstream=sys.stdout):
				repo = Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)

				#porcelain.clone(url, target='.')
				#repo = Gittle('.')

				#Set the origin
				config = repo.repo.get_config()
				config.set(('remote','origin'),'url',url)
				config.write_to_path()
			else:
				print command_help['clone']
开发者ID:jsbain,项目名称:shellista,代码行数:18,代码来源:shellista.py

示例12: clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
    def clone(self,clonedict):
        remote=clonedict['remote url']
        local=clonedict['local path']
        repo_name= os.path.join(self.view['repo'].base, local)

        if remote:
            try:
                repo = Gittle.clone(remote, repo_name, bare=False)
        
                #Set the origin
                config = repo.repo.get_config()
                config.set(('remote','origin'),'url',remote)
                config.write_to_path()
                self.view['repo'].txt=repo_name
                self.refresh()
            except Exception as e:
                console.hud_alert(e.message)
开发者ID:jmassob,项目名称:gitview,代码行数:19,代码来源:gitui.py

示例13: handle

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
    def handle(self, *args, **options):
        projects = Project.objects.all()

        for project in projects:
            print('Checking {0} for new commits'.format(project))
            if project.git_url:
                repo_path = '/tmp/' + project.slug
                try:
                    repo = Gittle(repo_path, project.git_url)
                    repo.pull()
                except:
                    try:
                        repo = Gittle.clone(project.git_url, repo_path)
                    except:
                        # put some logging here
                        repo = None
                if repo:
                    new_commits = []
                    for commit in repo.commit_info():
                        try:
                            prev_commit = repo.get_previous_commit(commit['sha'])
                            time = (datetime.fromtimestamp(commit['time']) + timedelta(hours=commit['timezone']/(60*60))).replace(tzinfo=pytz.utc)
                            try:
                                user_author = get_user_model().objects.get(email=commit['author']['email'])
                                string_author = None
                            except:
                                string_author = commit['author']['name']
                                user_author = None

                            summary = commit['message'].split('\n')[0][:45]
                            pcommit = ProjectCommit.objects.create(
                                project=project,
                                chash=commit['sha'],
                                message=commit['message'],
                                summary=summary,
                                user_author=user_author,
                                string_author=string_author,
                                created=time,
                                time=time,
                                diff=repo.diff(commit['sha'], prev_commit).next()['diff']
                            )
                            print(pcommit, ' added.')
                            new_commits.append(pcommit)
                        except:
                            pass
开发者ID:Code4Maine,项目名称:beehve,代码行数:47,代码来源:update_project_repos.py

示例14: whole_project

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
def whole_project(repo_url):
    
    real_repo_url = get_real_repo_url(repo_url)
    
    from gittle import Gittle
    
    try:
        repo_path = '/tmp/gittle_bare'
        repo = Gittle(repo_path)
    except: 
        repo = Gittle.clone(repo_url, repo_path)
    with open('%s/docs/index.rst' % repo_path, 'r') as index_page:
        file_content = index_page.read()
    initial_content = rst2html(file_content)
    #except:
    #    
    return render_template("project/home.html", 
        repo_url=repo_url, 
        repo=repo, 
        initial_content=initial_content,
        page_title="index.rst"
    )
开发者ID:evolvedlight,项目名称:recordthedocs,代码行数:24,代码来源:views.py

示例15: clone

# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import clone [as 别名]
 def clone(self,clonedict):
     remote=clonedict['remote url']
     local=clonedict['local path']
     repo_name= os.path.join(self.view['repo'].base, local)
     if not local:
         console.hud_alert('you must define a local path','error')
         return
     if remote and not remote=='https://github.com/':
         #for github urls, force it to end in .git
         if remote.find('github') and not remote.endswith('.git'):
             remote=remote+'.git'
         try:
             console.show_activity()
             repo = Gittle.clone(remote, repo_name, bare=False)
             console.hide_activity()
             #Set the origin
             config = repo.repo.get_config()
             config.set(('remote','origin'),'url',remote)
             config.write_to_path()
             self.view['repo'].text=local
             self.did_select_repo(self.view['repo'])
             console.hud_alert('clone successful')
         except urllib2.URLError:
             console.hud_alert('invalid remote url. check url and try again','error')
         except OSError:
             def overwrite(items):
                 import shutil
                 shutil.rmtree(os.path.join(repo_name,'.git'))
                 self.clone(clonedict)
             def cancel(items):
                 console.hud_alert('clone cancelled!','error')
             self.confirm(overwrite,'{} already has a .git folder. Overwrite?'.format(local),cancel)
         except:
             console.hud_alert('failed to clone. check traceback','error')
             raise
     else:
         console.hud_alert('You must specify a valid repo to clone','error')
开发者ID:c0ns0le,项目名称:Pythonista,代码行数:39,代码来源:gitui.py


注:本文中的gittle.Gittle.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。