def gitPush():
    logging.info('*** Versioning files and pushing to 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.stage(repo.pending_files)
        repo.commit(message=commitMessage)
        repo.push()
def gitPush():
    logging.info('*** Versioning files and pushing to 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.stage(repo.pending_files)
        repo.commit(message=commitMessage)
        repo.push()
Ejemplo n.º 3
0
class GitGittle(BaseGit):
    def __init__(self):
        self.repo = None

    def git_init(self):
        try:
            # Init repository
            logger.debug("Local repository path:{}, Git server url: {}".format(
                conf.git.local_repository_path, conf.git.git_server_url))
            self.repo = Gittle(conf.git.local_repository_path,
                               origin_uri=conf.git.git_server_url)

            logger.info("Pulling from git..")
            # Update local working copy
            self.repo.pull()

            logger.info("GitGittle - Git is up to date !")

        except Exception as exc:
            logger.error(
                "GitGittle - Failed to initialize Git. Reason: {}".format(
                    exc.message))
            raise GitInitError(exc.message)

    def git_upload_changes(self):
        commit_id = ""
        try:

            logger.info("Commit changes in progress ..")
            # Stage modified files
            self.repo.stage(self.repo.pending_files)

            commit_message = conf.git.commit_message_format.format(
                self.repo.added_files)
            # Commit the change
            commit_id = self.repo.commit(conf.git.commit_user,
                                         conf.git.commit_email, commit_message)

            logger.info("Commit details: commit_user:{}, commit_email:{}, "
                        "commit_message:{}, commit_id:{}".format(
                            conf.git.commit_user, conf.git.commit_email,
                            commit_message, commit_id))

            # Push to repository
            self.repo.push()

        except Exception as exc:
            logger.error("GitGittle - Filed to upload file to git.")
            raise GitUploadError("Failed to upload file to Git")

        return commit_id

    def validate_git(self):
        pass
Ejemplo n.º 4
0
		def git_push(args):
			from gittle import GittleAuth
			if len(args) == 1 or len(args) == 3:
				if len(args) > 1:
					user = args[1]
					pw = args[2]
					repo = Gittle('.')
					print repo.push_to(args[0],username=user,password=pw)
				else:
					repo = Gittle('.', origin_uri=args[0])
					repo.push()
			else:
				print command_help['push']
Ejemplo n.º 5
0
class GPassGit:

    #Creates a Git object
    def __init__(self, repoPath):
        self.repoPath = repoPath
        self.repo = None
        if self.isRepoSet():
            self.repo = Gittle(self.repoPath)

    #Check For Git Repo
    def isRepoSet(self):
        if os.path.isfile(self.repoPath + '/.git/config'):
            return True
        return False

    def init(self, repoPath):
    	self.repo = Gittle.init(repoPath)
    	print("Created Repo")

    def add(self, filePath):
    	self.repo.stage([filePath])

    def commit(self, user, em, msg):
    	self.repo.commit(
            name=user,
            email=em,
            message=msg
        )

    # Authentication with RSA private key
    def auth(self, key):
        key_file = open(key)
        repo.auth(pkey=key_file)

    def push(self, key):
        self.auth(key)
        self.repo.push()

    def pull(self, key):
        self.auth(key)
        self.repo.pull()

    def acp(self, filepath, user, em, msg):
    	self.add(filepath)
    	self.commit(user, em, msg)
    	self.push(key)
        
Ejemplo n.º 6
0
def GitUpload(file, Name, Email, Password, Repository, Message="Some uploads"):

    origin_uris = Repository
    if not origin_uris.startswith(Name):
        origin_uris = Name + "/" + origin_uris
    if not origin_uris.startswith("https://github.com/"):
        origin_uris = "https://github.com/" + origin_uris
    if not origin_uris.endswith(".git"):
        origin_uris = origin_uris + ".git"

    path = os.getcwd()

    # Gittle.clone() 会将当前目录下的文件下载到本地,并初始化git工作路径,上传文件正常
    # repo = Gittle.clone("https://github.com/fengfeng0918/gittle.git", path)
    # Gittle.init() 初始化git工作路径,并没有将远程仓库信息拉到本地,上传(push)文件时会将远程库清空
    # repo = Gittle.init(path,origin_uri="https://github.com/fengfeng0918/gittle.git")

    # git init  以下流程正常!!!
    if not os.path.exists(".git"):
        local_repo = Gittle.init(path)
        # local_repo = Gittle.clone(origin_uris,path)
        bares = False  #不会删除远端,重写本地
    else:
        local_repo = Repo(path)
        bares = True  # 不会删除远端,不重写本地

    repo = Gittle(local_repo, origin_uris)
    repo.fetch(bare=bares)

    # Stage file
    if not isinstance(file, list):
        file = [file]
    repo.stage(file)

    # Commiting
    repo.commit(name=Name, email=Email, message=Message, files=file)

    # add remote
    repo.add_remote('origin', origin_uris)

    # Push
    repo.auth(username=Name, password=Password)  # Auth for pushing
    repo.push()
Ejemplo n.º 7
0
from gittle import Gittle

from config import repo_path, repo_url, key_file

# Gittle repo
g = Gittle(repo_path, origin_uri=repo_url)

# Authentication
g.auth(pkey=key_file)

# Do push
g.push()