Example #1
0
def process_update(process):
    process_control(process, 'stop')  # stop process
    if process == 'bgpapi_8108':
        filename = 'bgpapi_' + time.strftime(
            '%Y%m%d%H%M%S', time.localtime(time.time())) + '.tar.gz'
        path = '/home/API/bgpapi'
        mv_path = '/home/API/backup'
        make_targz('/home/API/' + filename, path)  # backup
        os.system('mv %s %s' % ('/home/API/' + filename, mv_path))
        os.system("rm -rf %s" % path)  # delete
        repo_url = 'git@mgrser:root/bgpapi.git'
        Gittle.clone(repo_url, path)  # git clone
        repo = Gittle(path, origin_uri='git@mgrser:root/bgpapi.git')
        repo.switch_branch('master')
        repo.pull()
    elif process == 'bgpapi_8109':
        path = '/home/API/bgpapi_ha'
        os.system("rm -rf %s" % path)  # delete
        repo_url = 'git@mgrser:root/bgpapi.git'
        Gittle.clone(repo_url, path)  # git clone
        repo = Gittle(path, origin_uri='git@mgrser:root/bgpapi.git')
        repo.switch_branch('master')
        repo.pull()
    else:
        print('You cannot do with this %s' % process)
    process_control(process, 'start')  # start process
    print('%s has been updated.' % process)
Example #2
0
    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)
 def _clone_sync_file(self):
     try:
         if os.path.exists(self.sync_tmp_file):
             shutil.rmtree(self.sync_tmp_file)
         Gittle.clone(self.sync_file_project, self.sync_tmp_file)
     except Exception, e:
         print e
         sys.exit(1)
Example #4
0
 def getFiles(self):
     try:
         if os.path.exists(self.tmp_path):
             shutil.rmtree(self.tmp_path)
         Gittle.clone(self.repo, self.tmp_path)
     except Exception, e:
         print e
         sys.exit(1)
Example #5
0
 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)
Example #6
0
    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
Example #7
0
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
Example #8
0
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
Example #9
0
def createTask(taskId, gitKey, gitAddress):
    """
    fortify 命令行调用
    fortify 使用手册 HPE_SCA_Guide_16.20.pdf
    :param taskId:
    :param gitKey:
    :param gitAddress:
    :return:
    """
    clonePath = os.path.join(BASE_DIR, "gitClone")
    outputPath = os.path.join(BASE_DIR, "reports")
    if not os.path.exists(clonePath):
        os.mkdir(clonePath)
    if not os.path.exists(outputPath):
        os.mkdir(outputPath)
    fortifyLogMsg(taskId=taskId, msg=u"拉取代码" + gitAddress, code=1)

    localPath = gitAddress.replace("http://", "").replace("https://", "").replace("/", "_").split("?")[0]
    localPath = localPath.replace("git@", "").replace(":", "_").replace(".git", "")
    localPath = os.path.join(clonePath, localPath)

    buildName = "_".join(localPath.split("_")[1:])

    try:
        if gitKey and gitAddress:
            from gittle.auth import GittleAuth
            # https://github.com/FriendCode/gittle/issues/18
            authkey = GittleAuth(pkey=gitKey)
            if not os.path.exists(localPath):
                Gittle.clone(gitAddress, local_path=localPath, auth=authkey)
            else:
                repo = Gittle(localPath, origin_uri=gitAddress, auth=authkey)
                repo.pull()
        else:
            if not os.path.exists(localPath):
                Gittle.clone(gitAddress, localPath)
            else:
                repo = Gittle(localPath, gitAddress)
                repo.pull()
    except Exception, e:
        # raise e
        fortifyLogMsg(taskId, u"任务拉取代码遇到异常" + str(e.message), "", code=2)
        return ""  # 结束任务
Example #10
0
File: git.py Project: zychen/stash
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'])
Example #11
0
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"]
Example #12
0
    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']
Example #13
0
 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()
Example #14
0
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']
Example #15
0
File: git.py Project: BBOOXX/stash
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'])
Example #16
0
def checkout(slist):
    fp = open(slist, 'r')

    lines = fp.readlines()

    for line in lines:
        line_list = line.split('\n')[0].split('\t')
        if len(line_list) == 4:
            repo_url = line_list[3]
            repo_path = line_list[1]
            try:
                repo = Gittle.clone(repo_url, repo_path)
            except:
                print('clone')
Example #17
0
    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
Example #18
0
    def clone(repo_info):
        repo_context = None
        try:
            repo_context = AgentGitHandler.create_git_repo_context(repo_info)

            if os.path.isdir(repo_context.local_repo_path):
                # delete local repo path if exists
                cartridgeagentutils.delete_folder_tree(
                    repo_context.local_repo_path)

            # create local repo path
            cartridgeagentutils.create_dir(repo_context.local_repo_path)

            #TODO: remove gittle stuff
            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
Example #19
0
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()
		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']
Example #21
0
		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']
Example #22
0
    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 urllib.error.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")
Example #23
0
def git_clone(args):
    if len(args) > 0:
        url = args[0]
        auth = gittle.GittleAuth(username='******',
                                 pkey=(os.path.join(os.environ['HOME'],
                                                    '.ssh/quentin')))
        repo = Gittle.clone(args[0],
                            args[1] if len(args) > 1 else '.',
                            auth,
                            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']
Example #24
0
    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)
Example #25
0
    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
Example #26
0
    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')
Example #27
0
def git_clone(args):
    if len(args) > 0:
        url = args[0]
        if len(args) > 1:
            args_1 = args[1]
        else:
            args_1 = os.path.split(args[0])[-1]
            if args_1.endswith('.git'):
                args_1 = args_1[:-4]
        repo = Gittle.clone(args[0], args_1, 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'])
Example #28
0
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"
    )
Example #29
0
 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')
Example #30
0
    def clone(self, key_file=None, username=None, password=None):
        '''
        clone the git repo

        :param key_file: string : None
        location of private key if you want to connect using RSA
        :param username: string : None
        username if you wnat to connect using basic authentication
        :param password: string : None
        password if you wnat to connect using basic authentication
        '''
        if self._cloned is False:
            if key_file is not None:
                # Authentication with RSA private key
                key_file = open(key_file)
                Gittle.clone(self.repo_url, self.repo_path, auth=GittleAuth(pkey=key_file))
            elif username is not None and password is not None:
                # With username and password
                Gittle.clone(self.repo_url, self.repo_path,
                             auth=GittleAuth(username=username, password=password))
            else:
                # Without anything , is it even possible?
                Gittle.clone(self.repo_url, self.repo_path)
Example #31
0
from gittle import Gittle

repo_path = '/Users/manas/tmp/munim'
repo_url = 'git://github.com/manasdk/munim'

repo = Gittle.clone(repo_url, repo_path)
Example #32
0
        break

osName = osList.get(os_name, None)
osBit = os_bits()
branchForTarget = "master"
if osName != None and osBit != None:
    branchForTarget = osName + osBit


def report_transfer(size, message):
    print "size : " + size + ", message : " + message


if isInstalled:
    repo = Gittle(repo_path,
                  origin_uri=repo_url,
                  report_activity=report_transfer)
else:
    repo = Gittle.clone(repo_url, repo_path, report_activity=report_transfer)

repo.switch_branch(branchForTarget)

commit_info = repo.commit_info(start=0, end=20)
print "repo.active_branch  : " + str(repo.active_branch)
print "repo.branches       : " + str(repo.branches)
print "repo.commits()      : " + str(repo.commits())
print "repo.head           : " + repo.head
print commit_info

# repo.pull(branch_name=branchForTarget)
Example #33
0
#coding:utf-8
# write  by  zhou

from gittle import Gittle, GittleAuth

auth = GittleAuth(
    pkey=
    '''-----BEGIN RSA PRIVATE KEY-----\nMIIEqAIBAAKCAQEAoGfRxmiQi5r4DJkd9cANJSswOm+yDf/zxHDZoq+41Aady+8e\n/s+ESvq3fF+3gOYMoYFkKGQ76Dz2JSRIb9bRAuVRZdgLkzbmVddKZ7D35OCqBAz+\nAXP2k82vOvHT+Y7y6/jn2anwOOahX4OTAhsOjd5G17OxvUkB28A1h70KYr/+2bY2\nMqRG69/5CiHSlB1gmZyxTJJrNHZeC8e6i9HYuJ6T0RcqVWVOH+MliZ4VrvhOK7n2\nrXQgG664OJOgMuWItq8XfJtH6B5+CGo5iQ3oG4IwlweSvevw0EG33d/7FNW+vn9g\nq7N9Km9cy0LFUWWJDgsrJsIhalmTGXjBdlDPMwIDAQABAoIBAQCSfR3Dz7yp8hW0\nE6WbyA95MU7zHwyB4ozxiooHG+l0oLI9CxzIYiWUABHPoO5J5k4EtNEOXjOjrQCx\n/Me2c30f4uMKWlp/0DRckqfduG07db1uw5q5Ivk+FCqCb1VB5L2OqRq72omKvX0E\naHm6A5GwGB2kYfPhRKpQ0OFSHF8+vFvT0zvMq2SDbNpPoGFXTgpELamBTk6vK27/\nL+6pEVivsIDHxxruVmFxD23uPIcsxWf+5LfeVL0OJ5JqlVK2OeLyvC7ZNDCYIyCO\nzkyS98EtiKJbW3lcDWPBNiwjNr7cOYN1Wnw3cR5DYbhIINLEzwaIrEe2MsnBvpgf\neBdNUjr5AoIAgQDASJpTMnNjmFtkIPv47Pgj4p94KadOnGrgtzkDHWTk648wpcNx\nYI9bZvddmq4UxupcCAGiKT5s42fhXLgoMc7Ens/Dwe2E7/kW2cfdksvhk5oeXQ7d\n0pPqklRE4XCRWLmuRFLascYEDXsSCOOluSlc/lcSE51fFhmTrzd8D8CXvwKCAIEA\n1Y8BFjrxZ1h047JDVFTHxY2JyxlYvRfF1DU7HhlfJo0HPc05EDpxaDnj77099JLh\n816/ctVqb/kGmKQFzvJD/BfXhL2yx5vZAfkmz/lEiSDLc8u0J+P87FlR0YrdedSS\n+W6JIOQ0xKkkeQx5o4Zh7SBpUQPwockDogZDjUdZhY0CggCAdNbpJ6rdYOSAjCxa\n0By2f5/ChRLSfjsf2qKbOyBOYagdn1Lqmucw1TqRD0jhhPCGEhwvWekz7JiWU+Oy\nZ4I0gVd7KhmaCZCETHVTNHlx+AVnvhGP6gx+Iyh9mklezIMceR89NXSWvXmvkfri\n0Z3c24wVPn+6vb/BFPOAhJtRzSMCggCABE0lEHWPdy1o7U0h3gj3HRuEsvqHtwdL\njMKlti18pSIiCzSe+ZyzvA2ucZ22Kb7rniNCZ+W0hxzU7S4gj9KBXAp+5MWNXEff\nTxLdnULABqMKdgKcVlFZPsltxHKvk0ycyTlYubje9zcQ7P87U/fY8RW+CUuzBQ8v\na4wEwEu3meECggCAHKGrk826p0yjUJP8+fQXAjqVAfbJbRcl4xAdQwaCKfuSizrk\nSXlIOfdLylhafu1CUjhPyfydW7V8ZraNt2wrKxN6q2u0XNHeauemRBH7oW+PVikW\nx08KPvxxGasYYJ4adHIYj8D5TO2AeH1Kb9STfewNTlnHv4rcjaPWMs0CEVk=\n-----END RSA PRIVATE KEY-----\n'''
)
repo = Gittle.clone("[email protected]:gongchang/gc36.git",
                    "~/testgittlessssss/",
                    auth=auth)
print repo.commits()
Example #34
0
File: git.py Project: apanly/gitftp
# -*- coding: utf-8 -*-
Example #35
0
    def post(self):
        #authuserList=['jino']
        #if not  self.get_current_user() in authuserList:
        #    self.write('unauthorized users')
        #    return

        parser = CappConfig(CONF)
        self.set_header('Content-Type', 'text/plain')
        #sid=self.request.arguments['sid']

        cid = self.get_argument('cid', None)
        if not cid:
            self.write('ERROR:invalid branch')
            return
        sid = self.get_argument('sid', None)
        if not sid:
            self.write('ERROR:invalid server')
            return
        dst = get_srvlist(sid)
        servname = parser.get('REPO', '%s.servname' % dst)
        host = parser.get('SERVER', '%s.hostname' % servname)
        user = parser.get('SERVER', '%s.username' % servname)
        pwds = parser.get('SERVER', '%s.password' % servname)
        keyd = parser.get('PATH', 'keysdire')
        pkey = os.path.join(keyd, parser.get('SERVER',
                                             '%s.pkeyfile' % servname))
        if not os.path.exists(pkey):
            self.write('ERROR:pkeyfile not exists or chmod 600 %s user %s' %
                       (pkey, getpass.getuser()))
            return
        if int(oct(os.stat(pkey).st_mode)[-3:]) != 600:
            self.write('MESSAGE:pls chmod 600 %s user %s' %
                       (pkey, getpass.getuser()))
            return
        bpre = parser.get('SERVER', '%s.branchpx' % servname)
        port = int(parser.get('SERVER', '%s.port' % servname))

        sdir = parser.get('REPO', '%s.syncdirs' % dst)
        item = parser.get('REPO', '%s.projitem' % dst)
        cper = parser.get('REPO', '%s.permissi' % dst)
        if not re.match(bpre.replace(',', '|'), cid):
            self.write('ERROR:branch not right')
            return
        #for b in bpre.split(','):
        #    if not re.match(b,cid):
        #        self.write('ERROR:branch not right')
        #        return

        workdirs = parser.get('PATH', 'workdirs')
        verconfile = os.path.join(workdirs, 'vercnf')
        verconf = CappConfig(verconfile)
        try:
            vers = verconf.get('REPO', '%s.versions' % dst)
        except:
            vers = ''

        dskey = os.path.join(keyd, parser.get('PATH', 'deploykf'))
        if not os.path.exists(dskey):
            self.write('ERROR:deploykf not exists or chmod 600 %s user %s' %
                       (dskey, getpass.getuser()))
            return
        if int(oct(os.stat(dskey).st_mode)[-3:]) != 600:
            self.write('MESSAGE:pls chmod 600 %s user %s' %
                       (dskey, getpass.getuser()))
            return
        try:
            authk = GittleAuth(pkey=dskey)
        except:
            self.write("ERROR:deploy key valid")
            return

        try:
            repo = Gittle(os.path.join(workdirs, dst),
                          origin_uri=repo_url[item],
                          auth=authk)
        except:
            try:
                repo = Gittle.clone(repo_url[item],
                                    os.path.join(workdirs, dst),
                                    auth=authk)
            except:
                self.write(
                    'ERROR:deploy key not permission or confdirs cannot write')
                return
        try:
            repo.switch_branch('master')
            repo.pull_from(repo_url[item], cid)
            repo.switch_branch(cid)
            lastcommit = repo.commit_info(0, 1, cid)[0]
            self.write('%s\t%s\n%s\n' %
                       (lastcommit['summary'][:60], lastcommit['sha'][:8],
                        lastcommit['committer']['name']))
        except:
            try:
                rmtree(os.path.join(workdirs, dst))
                repo = Gittle.clone(repo_url[item],
                                    os.path.join(workdirs, dst),
                                    auth=authk)
                repo.switch_branch('master')
                repo.pull_from(repo_url[item], cid)
                repo.switch_branch(cid)
                lastcommit = repo.commit_info(0, 1, cid)[0]
                self.write('%s\t%s\n%s\n' %
                           (lastcommit['summary'][:60], lastcommit['sha'][:8],
                            lastcommit['committer']['name']))
            except Exception as e:
                self.write('confdirs cannot write')
                return

        parser2 = CappConfig(parser.get('PATH', 'excludef'))
        try:
            parser2.items('%s%s%s' % (servname, item, dst))
        except:
            self.write('ERROR:excludef no section %s%s%s' %
                       (servname, item, dst))
            return
        self.write('SETP1 \tstart:\n')
        for sfile, dfile in parser2.items('%s%s%s' % (servname, item, dst)):
            ssdir = os.path.join(parser.get('PATH', 'confdirs'),
                                 '%s%s%s' % (servname, item, dst))
            ddir = os.path.join(workdirs, dst)
            if dfile.startswith('/'): dfile = dfile[1:]
            err, out = rsync(os.path.join(ssdir, sfile),
                             os.path.join(ddir, dfile))

            if len(err) is 0:
                reChar = re.compile(
                    'send*.*list|send*.*sec|total size*.*|rsync:')

                self.write('%s' % reChar.sub('', out))

            else:
                reChar = re.compile('rsync error:*.*|rsync: link_stat|rsync:')
                self.write('ERROR:%s' % reChar.sub('', err))
                return
        self.write('SETP1 \tend.\n')

        conflist = os.path.join(ddir, '.git/conflist')
        if os.path.exists(conflist):
            rsync_arg = '--exclude=.git --exclude-from=%s' % os.path.join(
                ddir, '.git/conflist')
        else:
            rsync_arg = '--exclude=.git'

        local_dir = '%s/' % ddir
        remote_dir = '%s@%s:%s' % (user, host, sdir)

        err, _ = sshto(host, int(port), user, pwds, pkey).exe_cmdOne('')
        if err:
            self.write('ERROR:target server auth failure')
            return

        only_com = False
        try:
            precmd, aftcmd = parser.get('REPO', '%s.cmdexecu' % dst).split(',')
        except:
            precmd = parser.get('REPO', '%s.cmdexecu' % dst)
            aftcmd = ''
        if os.path.isfile(precmd): precmd = open(precmd).read()
        if os.path.isfile(aftcmd): aftcmd = open(aftcmd).read()

        if self.get_argument('check', None) is None:
            if not self.get_current_user()['username'] + '|c' in cper:
                if precmd:
                    precmd_err, precmd_out = sshto(host, int(port), user, pwds,
                                                   pkey).exe_cmdOne(precmd)
                    if len(precmd_err) is 0:
                        self.write('EXEC PRE:\n%s\n' % precmd_out)
                    else:
                        self.write('ERROR: exec pre\n%s\n' % precmd_err)
                        return

                err2, out2 = rsync(local_dir,
                                   remote_dir,
                                   arg=rsync_arg,
                                   pkey=pkey)

                if aftcmd:
                    aftcmd_err, aftcmd_out = sshto(host, int(port), user, pwds,
                                                   pkey).exe_cmdOne(aftcmd)
                    if len(aftcmd_err) is 0:
                        self.write('EXEC AFT:\n%s\n' % aftcmd_out)
                    else:
                        self.write('ERROR: exec aft\n%s\n' % aftcmd_err)

                if out2:
                    config = ConfigParser.RawConfigParser()
                    if vers:
                        vers = vers.split(',')
                        if len(vers) == 1: vers.append(cid)
                        vers[1] = vers[0]
                        vers[0] = cid

                        config.read(verconfile)
                        config.set('REPO', '%s.versions' % dst, ','.join(vers))
                        with open(verconfile, 'w') as configfile:
                            config.write(configfile)
                    else:
                        config.read(verconfile)
                        config.set('REPO', '%s.versions' % dst, cid)
                        config.write(open(verconfile, 'w'))

            else:
                self.write('ERROR:no publishing rights\n')
                return

        else:
            self.write('EXEC PRE:\n%s\n' % precmd)
            err2, out2 = rsync(local_dir,
                               remote_dir,
                               arg=rsync_arg,
                               pkey=pkey,
                               check=True)
            self.write('EXEC AFT:\n%s\n' % aftcmd)
            only_com = True

        if len(err2) is 0:
            reChar = re.compile('send*.*list|send*.*sec|total size*.*|rsync:')
            self.write('SETP2 \tstart:\n')
            self.write('%s' % reChar.sub('', out2))
            self.write('SETP2 \tend.\n')
        else:
            reChar = re.compile('rsync error:*.*|rsync: link_stat|rsync:')
            self.write('%s' % reChar.sub('', err2))

        if only_com:
            self.write('MESSAGE:only for comparison is not pub\n')
        return
 def clone(self):
     if not os.listdir(self.repo_path):
         repo = Gittle.clone(self.repo_url, self.repo_path)
Example #37
0
		def git_clone(args):
			if len(args) > 0:
				Gittle.clone(args[0], args[1] if len(args)>1 else '.', bare=False)
			else:
				print command_help['clone']
Example #38
0
# Samy Pessé <*****@*****.**>
#
# This program is free software; you can redistribute it and/or
# modify it only under the terms of the GNU GPLv2 and/or the Apache
# License, Version 2.0.  See the COPYING file for further details.

from gittle import Gittle

path = '/tmp/gittle_bare'

# Clone repository
repo = Gittle.clone('git://github.com/FriendCode/gittle.git', path)

# Information
print "Branches :"
print repo.branches
print "Commits :"
print repo.commit_count

# Commiting
fn = 'test.txt'
filename = os.path.join(path, fn)

# Create a new file
fd = open(filename, 'w+')
fd.write('My file commited using Gittle')
fd.close()

# Stage file
repo.stage(fn)
Example #39
0
import sys
import traceback
from gittle import Gittle, GittleAuth

repo_path = '/Users/manas/tmp/st2-contrib'
repo_url = 'git://github.com/stackstorm/st2-contrib'
key = '/Users/manas/.ssh/id_rsa'

try:
    auth = GittleAuth(pkey=key)
    repo = Gittle.clone(repo_url, repo_path, auth=auth)
except:
    ex_t, ex, tb = sys.exc_info()
    print str(ex)
    print ''.join(traceback.format_tb(tb))
Example #40
0
# Samy Pessé <*****@*****.**>
#
# This program is free software; you can redistribute it and/or
# modify it only under the terms of the GNU GPLv2 and/or the Apache
# License, Version 2.0.  See the COPYING file for further details.

from gittle import Gittle

path = '/tmp/gittle_bare'

# Clone repository
repo = Gittle.clone('git://github.com/FriendCode/gittle.git', path)

# Information
print("Branches :")
print(repo.branches)
print("Commits :")
print(repo.commit_count)

# Commiting
fn = 'test.txt'
filename = os.path.join(path, fn)

# Create a new file
fd = open(filename, 'w+')
fd.write('My file commited using Gittle')
fd.close()

# Stage file
repo.stage(fn)
import tensorflow as tf
from zipfile import ZipFile
from collections import Counter

sess = tf.Session()

local_repository = 'temp_rnn'

if tf.__version__[0] < '1':
    print('hah your tensorflow version < 1? ' + tf.__version__)
    from tensorflow.models.rnn.tanslate import seq2seq_model
else:
    if not os.path.exists(local_repository):
        from gittle import Gittle
        tf_model_repository = "https://github.com/tensorflow/models"
        repo = Gittle.clone(tf_model_repository, local_repository)
        sys.path.insert(0, 'temp_rnn/tutorials/rnn/translate/')
        import seq2seq_model as seq2seq_model
        import data_utils as data_utils

learning_rate = 0.1
lr_decay_rate = 0.99
lr_decay_every = 100
max_gradient = 5.0
batch_size = 50
num_layers = 3
rnn_size = 500
layer_size = 512
generations = 10000
vocab_size = 10000
save_every = 1000