本文整理汇总了Python中gittle.Gittle类的典型用法代码示例。如果您正苦于以下问题:Python Gittle类的具体用法?Python Gittle怎么用?Python Gittle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gittle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_repo
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)
示例2: gitPull
def gitPull():
logging.info('*** Pulling changed files from remote repository ***')
destinations = [dataDestination, PDFdestination]
remotes = ['dataRemote', 'PDFRemote']
for d, r in zip(destinations, remotes):
repo = Gittle(d, origin_uri=config.get('Git', r))
repo.pull()
示例3: git_checkout
def git_checkout(args):
if len(args) == 1:
repo = Gittle('.')
#repo.checkout('refs/heads/{0}'.format(args[0]))
repo.switch_branch('{0}'.format(args[0]))
else:
print command_help['checkout']
示例4: __init__
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)
示例5: git_commit
def git_commit(args):
if len(args) == 3:
try:
repo = Gittle('.')
print repo.commit(name=args[1],email=args[2],message=args[0])
except:
print 'Error: {0}'.format(sys.exc_value)
else:
print command_help['commit']
示例6: git_pull
def git_pull(args):
if len(args) <= 1:
repo = Gittle('.')
url = args[0] if len(args)==1 else repo.remotes.get('origin','')
if url:
repo.pull(origin_uri=url)
else:
print 'No pull URL.'
else:
print command_help['git pull']
示例7: __init__
def __init__(self, path):
try:
self.gittle = Gittle(path)
except NotGitRepository:
self.gittle = Gittle.init(path)
# Dulwich repo
self.repo = self.gittle.repo
self.path = path
示例8: update_repo
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()
示例9: init_repo_if_empty
def init_repo_if_empty(self,repo_name):
repopath=os.path.join(self.view['repo'].base,repo_name)
self.g= Gittle.init(repopath,bare=False )
self.g.commit('name','email','initial commit')
self.view['repo'].text=repo_name
console.hud_alert('Repo {} created'.format(repo_name))
self.did_select_repo(self.view['repo'])
示例10: get_readme
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
示例11: get_requirements
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
示例12: pull
def pull(self):
'''
pull the latest version
'''
self.clone()
self.repo = Gittle(self.repo_path, origin_uri=self.repo_url)
self.repo.pull()
示例13: init_repo_if_empty
def init_repo_if_empty(self,repo_name,gitpath):
if not os.path.exists(gitpath):
self.g= Gittle.init(gitpath,bare=False )
self.g.commit('name','email','initial commit')
self.view['repo'].text=repo_name
console.hud_alert('Repo {} created'.format(repo_name))
self.refresh()
示例14: clone
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
示例15: init
def init(path):
try:
repo = Gittle.init(path)
return repo
except:
AgentGitHandler.log.exception("Initializing local repo at %r failed" % path)
raise Exception("Initializing local repo at %r failed" % path)