Esempio n. 1
0
def run():
    jenkins_project = args.projectName
    jenkins_build_number = args.buildNumber

    if not jenkins.find_if_build_is_green(jenkins_project,
                                          jenkins_build_number):
        print("Build #" + jenkins_build_number + " of '" + jenkins_project +
              "' is not a green build.")
        sys.exit(1)

    repo_url = jenkins.find_github_repo_url_from_build(jenkins_project)

    git = Git(WORKSPACE, repo_url)

    commit_id = jenkins.find_commit_id_from_build(jenkins_project,
                                                  jenkins_build_number)
    verbose("commit_id=" + commit_id)

    repo_name = git.repo_name()
    verbose("repo_name=" + repo_name)

    git.clone()
    verbose("Git repo '" + repo_name + "' cloned to " + WORKSPACE)

    most_recent_tag = git.describe(commit_id)
    verbose("Most recent release: " + most_recent_tag)

    new_version_number = lib.read_user_preferred_version(
        repo_name, most_recent_tag)

    git.tag(commit_id, "release/" + new_version_number)
Esempio n. 2
0
    def sched_builder(self):
        for project in sorted(Project.get_all(), key=lambda p: p.name):
            if (project.name == ""):
                continue
            try:
                log.msg("checking project: %s" % project.name)
                if project.is_building():
                    log.msg("project %s still building, skip" % project.name)
                    continue

                branch = "master"
                git = Git(project)
                if os.path.isdir(git.workdir):
                    git.checkout_branch(branch)
                    git.pull()
                else:
                    git.clone(branch)

                if not os.path.isdir(git.workdir):
                    continue

                for remote_branch in git.branches(remote=True):
                    git.checkout_remote_branch(remote_branch.replace('origin/', ''))

                for release in ('stable', 'testing', 'unstable'):
                    if project.last_tag(release) != git.last_tag(release):
                        try:
                            _, version = git.last_tag(release).split('_')
                            log.msg("new %s tag, building version: %s" % (release, version))
                            d = threads.deferToThread(self.send_job, project.name, branch, release, version)
                        except Exception, e:
                            log.msg("tag not parsed: %s:%s" % (project.name, git.last_tag(release)))

            except Exception, e:
                log.err(e)
Esempio n. 3
0
 def clone(self, url=None, to_path=None, branch=None):
     Log.info(Status["STAT_GET_PACKAGE"] % url)
     g = Git(to_path)
     g.clone(url or self.github_url)
     if branch:
         g.checkout(branch)
     return True
Esempio n. 4
0
 def test_describe_never_tagged_before(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     lib.call_and_exit_if_failed(
         'git tag -a release/0.1.1 -m \'releasing version\'')
     latest_tag = git.describe()
     self.assertEqual(latest_tag, "0.1.1")
Esempio n. 5
0
def run():
    jenkins_project = args.projectName
    jenkins_build_number = args.buildNumber

    if not jenkins.find_if_build_is_green(jenkins_project, jenkins_build_number):
        print "Build #" + jenkins_build_number + " of '" + jenkins_project + "' is not a green build."
        sys.exit(1)

    repo_url = jenkins.find_github_repo_url_from_build(jenkins_project)

    git = Git(WORKSPACE, repo_url)

    commit_id = jenkins.find_commit_id_from_build(jenkins_project, jenkins_build_number)
    verbose("commit_id=" + commit_id)

    repo_name = git.repo_name()
    verbose("repo_name=" + repo_name)

    git.clone()
    verbose("Git repo '" + repo_name + "' cloned to " + WORKSPACE)

    most_recent_tag = git.describe()
    verbose("Most recent release: " + most_recent_tag)

    new_version_number = lib.read_user_preferred_version(repo_name, most_recent_tag)

    git.tag(commit_id, "release/" + new_version_number)
Esempio n. 6
0
 def test_update(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) != 1)
     os.chdir(test_repo_dir)
     with open("ANOTHER_FILE.txt", "a") as the_file:
         the_file.write("Another file")
     lib.call_and_exit_if_failed("git add .")
     lib.call_and_exit_if_failed('git commit -m "another commit"')
     git.update()
     self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) == 1)
Esempio n. 7
0
 def test_update(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     self.assertTrue(
         os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) !=
         1)
     os.chdir(test_repo_dir)
     with open('ANOTHER_FILE.txt', 'a') as the_file:
         the_file.write('Another file')
     lib.call_and_exit_if_failed('git add .')
     lib.call_and_exit_if_failed('git commit -m "another commit"')
     git.update()
     self.assertTrue(
         os.path.exists(os.path.join(test_repo_dir, "ANOTHER_FILE.txt")) ==
         1)
def cloneOrCheckout(base_path, repo):
	git = Git()
	repo_path = os.path.join(base_path, repo['name'])
	print (repo_path)
	try:
		os.chdir(repo_path)
	except OSError:
		os.chdir(base_path)
		git.clone(repo['base_url'] + repo['name'])
		os.chdir(repo_path)
		cloned = True
	finally:
		git.fetch()
		git.checkout(repo['branch'])
		os.chdir(base_path)
def cli(debug:bool, update:bool):
    """ do the needful """
    setup_logging(debug, logger)

    hangnail_data = []
    try:
        if os.path.exists(DATA_FILENAME):
            hangnail_data += json.load(open(DATA_FILENAME,'r'))
    except Exception as error_message:
        logger.error("Couldn't load {}, {}", DATA_FILENAME, error_message)

    # print(dir(repo))

    if update:
        if not os.path.exists(SOURCEREPO):
            logger.error("Can't find source repo: {}", SOURCEREPO)
            g = Git()
            g.clone(REMOTE_URL, SOURCEREPO)
        else:
            g = Git(SOURCEREPO)
            g.pull()

    if not os.path.exists(SIGNATURE_DIR):
        logger.error("Can't find signatures dir: {}", SIGNATURE_DIR)
        sys.exit(1)


    seen_keys = []
    for filename in os.listdir(SIGNATURE_DIR):
        full_filename = os.path.join(SIGNATURE_DIR,filename)
        signature = handle_signature_file(full_filename)
        logger.debug(signature)
        for key in signature:
            if key not in seen_keys:
                seen_keys.append(key)
        if signature not in hangnail_data:
            hangnail_data.append(signature)

    logger.debug("Keys seen: {}", seen_keys)

    if update:
        logger.info("Writing file...")
        with open(DATA_FILENAME, 'w') as file_handle:
            json.dump(obj=hangnail_data,fp=file_handle)
Esempio n. 10
0
    def _updateRepo(self, reponame):
        remotepath = self.repos.get(reponame, "path")
        submodules = self.repos.get(reponame,
                                    "submodules") if self.repos.has_option(
                                        reponame, "submodules") else False
        localpath = os.path.join(self.repodir, reponame)

        os.umask(0o007)  # create repo content not readable to others
        if not os.path.isdir(localpath):
            g = Git()
            g.clone(remotepath, localpath)

            repo = Repo(localpath)

            if submodules:
                repo.git.submodule("init")

            # not-working umask workaround
            p = subprocess.Popen(["chmod", "g+w", localpath])
            p.wait()
        else:
            repo = Repo(localpath)
            try:
                repo.git.update_index("--refresh")
            except GitCommandError:
                pass  # it's fine, we'll reset
            # We use wrapped API (direct git command calls) rather than calling semantic GitPython API.
            # (e.g. repo.remotes.origin.pull() was replaced by repo.git.pull("origin"))
            repo.git.reset("--hard", "master")
            #repo.git.clean("-f")
            repo.git.pull("origin")

            if submodules:
                repo.git.submodule("init")
                repo.git.submodule("foreach", "git", "fetch")
                repo.git.submodule("update")

        # now set correct group (same as build user)
        usr = self.repos.get(reponame, "build_usr")
        p = subprocess.Popen(["chgrp", usr, "-R", "-f", localpath])
        p.wait()

        return repo
Esempio n. 11
0
    def _updateRepo(self, reponame):
        remotepath = self.repos.get(reponame, "path")
        submodules = self.repos.get(reponame, "submodules") if self.repos.has_option(reponame, "submodules") else False
        localpath = os.path.join(self.repodir, reponame)

        os.umask(0o007)  # create repo content not readable to others
        if not os.path.isdir(localpath):
            g = Git()
            g.clone(remotepath, localpath)

            repo = Repo(localpath)

            if submodules:
                repo.git.submodule("init")

            # not-working umask workaround
            p = subprocess.Popen(["chmod", "g+w", localpath])
            p.wait()
        else:
            repo = Repo(localpath)
            try:
                repo.git.update_index("--refresh")
            except GitCommandError:
                pass  # it's fine, we'll reset
            # We use wrapped API (direct git command calls) rather than calling semantic GitPython API.
            # (e.g. repo.remotes.origin.pull() was replaced by repo.git.pull("origin"))
            repo.git.reset("--hard", "master")
            # repo.git.clean("-f")
            repo.git.pull("origin")

            if submodules:
                repo.git.submodule("init")
                repo.git.submodule("foreach", "git", "fetch")
                repo.git.submodule("update")

        # now set correct group (same as build user)
        usr = self.repos.get(reponame, "build_usr")
        p = subprocess.Popen(["chgrp", usr, "-R", localpath])
        p.wait()

        return repo
Esempio n. 12
0
    def sched_builder(self):
        for project in sorted(Project.get_all(), key=lambda p: p.name):
            if (project.name == ""):
                continue
            try:
                log.msg("checking project: %s" % project.name)
                if project.is_building():
                    log.msg("project %s still building, skip" % project.name)
                    continue

                branch = "master"
                git = Git(project)
                if os.path.isdir(git.workdir):
                    git.checkout_branch(branch)
                    git.pull()
                else:
                    git.clone(branch)

                if not os.path.isdir(git.workdir):
                    continue

                for remote_branch in git.branches(remote=True):
                    git.checkout_remote_branch(
                        remote_branch.replace('origin/', ''))

                for release in ('stable', 'testing', 'unstable'):
                    if project.last_tag(release) != git.last_tag(release):
                        try:
                            _, version = git.last_tag(release).split('_')
                            log.msg("new %s tag, building version: %s" %
                                    (release, version))
                            d = threads.deferToThread(self.send_job,
                                                      project.name, branch,
                                                      release, version)
                        except Exception, e:
                            log.msg("tag not parsed: %s:%s" %
                                    (project.name, git.last_tag(release)))

            except Exception, e:
                log.err(e)
Esempio n. 13
0
def init(ctx):
    """Run initial setup"""

    VerboseLog('Running init()', ctx)

    config_file = config_file_path()
    Config = ConfigParser.ConfigParser()

    if not config_exists():
        VerboseLog('Initializing first set up.', ctx)

        f = open(config_file, 'w+')
        os.makedirs(dot_dir_path())

        Config.add_section('options')

        VerboseLog('Requesting user options for initial settings.', ctx)

        value = click.prompt('GitHub user name', confirmation_prompt=True)
        Config.set('options', 'gitname', value)

        value = click.prompt('GitHub repo name', default='dotfiles')
        Config.set('options', 'reponame', value)

        Config.write(f)
        f.close()

        VerboseLog('Options set.', ctx)
        VerboseLog('Cloning repo into $HOME/.dot/', ctx)

        git = Git(home(), Conf('options', 'gitname'),
                  Conf('options', 'reponame'))
        return_code = git.clone()
        VerboseLog('git.clone() return_code was ' + str(return_code), ctx)
        if return_code == 0:
            click.secho(
                '\ndot is initalized. Run `dot pull` to pull dotfiles,\nor `dot track [dotfile]` if you\'ve never\nused dot. Also see `dot --help`.\n',
                fg='green')
        else:
            click.secho(
                '\ndot could not pull your repo from GitHub.\nRun `dot clean` followed by `dot init`\nto start over.\n\n(You may want to check your prerequisites\nat https://github.com/kylefrost/dot-cli#prerequisites.)\n',
                fg='red')
    else:
        VerboseLog('Is not initial set up.', ctx)
        click.secho(
            'You already set up dot. Run `dot config [option] [value]` to\nchange a config value, or edit '
            + config_file + '. To start\nover, run `dot clean`.\n',
            fg='yellow')
Esempio n. 14
0
def init(ctx):
    """Run initial setup"""

    VerboseLog('Running init()', ctx)

    config_file = config_file_path()
    Config = ConfigParser.ConfigParser()

    if not config_exists():
        VerboseLog('Initializing first set up.', ctx)

        f = open(config_file, 'w+')
        os.makedirs(dot_dir_path())

        Config.add_section('options')

        VerboseLog('Requesting user options for initial settings.', ctx)

        value = click.prompt('GitHub user name', confirmation_prompt=True)
        Config.set('options', 'gitname', value)

        value = click.prompt('GitHub repo name', default='dotfiles')
        Config.set('options', 'reponame', value)

        Config.write(f)
        f.close()

        VerboseLog('Options set.', ctx)
        VerboseLog('Cloning repo into $HOME/.dot/', ctx)

        git = Git(home(), Conf('options', 'gitname'), Conf('options', 'reponame'))
        return_code = git.clone()
        VerboseLog('git.clone() return_code was ' + str(return_code), ctx)
        if return_code == 0:
            click.secho('\ndot is initalized. Run `dot pull` to pull dotfiles,\nor `dot track [dotfile]` if you\'ve never\nused dot. Also see `dot --help`.\n', fg='green')
        else:
            click.secho('\ndot could not pull your repo from GitHub.\nRun `dot clean` followed by `dot init`\nto start over.\n\n(You may want to check your prerequisites\nat https://github.com/kylefrost/dot-cli#prerequisites.)\n', fg='red')
    else:
        VerboseLog('Is not initial set up.', ctx)
        click.secho('You already set up dot. Run `dot config [option] [value]` to\nchange a config value, or edit ' + config_file + '. To start\nover, run `dot clean`.\n', fg='yellow')
Esempio n. 15
0
 def test_describe_never_tagged_before(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     latest_tag = git.describe()
     self.assertEqual(latest_tag, "0.0.0")
Esempio n. 16
0
 def test_tag(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     git.tag(git.latest_commit_id(), "release/1.2.3")
     tag_query = lib.call('git describe --abbrev=0 --match release/*')
     self.assertEqual(tag_query.stdout.read().strip(), "release/1.2.3")
Esempio n. 17
0
def cloneAll(destination='.'):
    repos = GithubRepos()
    for repoUrl in repos.repoUrls:
        Git.clone(repoUrl, destination)
if os.path.exists(icons_dir):
    # Clean up old work directory
    print(f'Cleaning icons directory {icons_dir}')
    shutil.rmtree(icons_dir)

print('Creating work directories')
if not os.path.exists(build_dir):
    os.mkdir(build_dir)
if not os.path.exists(icons_dir):
    os.mkdir(icons_dir)

if not os.path.exists(md_git_dir):
    print(f'Cloning MaterialDesign repository into {build_dir}')
    repo = Git(build_dir)
    result = repo.clone(MDI_REPO)
else:
    print(f'Pulling changes from MaterialDesign repository into {md_git_dir}')
    repo = Repo(md_git_dir)
    remote = repo.remotes[0]
    remote.pull()

svg_files_count = len(fnmatch.filter(os.listdir(svg_path), '*.svg'))
print(f'Found {svg_files_count} files in {svg_path}')

# Create bitmaps
for svg_file in glob.iglob(os.path.join(svg_path, '*.svg')):
    file_name = Path(os.path.basename(svg_file)).stem
    print(f'Processing {file_name}.svg', end='')

    # Load SVG file and save as PNG for PIL
Esempio n. 19
0
def clone_git_repo(url, local_path):
    git_repo = Git(local_path)
    git_repo.clone(url)
Esempio n. 20
0
class Project():
	def __init__(self):
		self.tree = ElementTree();
		self.git = Git()
		if not os.path.exists(PROJECT_CONFIG_PATH):
			os.mkdir(PROJECT_CONFIG_PATH)
		try:
			self.tree.parse(PROJECT_CONFIG_FILE)
		except:
			root = Element('Project', {'name':os.path.basename(os.getcwd())})
			self.tree._setroot(root)

	def save(self):
		self.tree.write(PROJECT_CONFIG_FILE, xml_declaration=True, method="xml")

	def iter(self):
		return self.tree.iter('SubProject')

	def find(self, name):
		for i in self.iter():
			if i.get('name') == name:
				return i

	def inSubProject(self):
		cwd = os.getcwd()
		for node in self.iter():
			name = node.get('name')
			print("")
			print("On:%s" % name)
			print("***************************************")
			os.chdir("/".join([cwd, name]))
			yield
			print("***************************************")

	def clone(self):
		for module in self.iter():
			self.git.clone(module)

	def __init_module(self, module):
		if not os.path.exists(module):
			print("module %s not exists." % module)
			return None
		cwd = os.getcwd()
		os.chdir("/".join([cwd, module]))
		if self.git.is_repo():
			node = Element('SubProject')
			node.set("name", module)
			current_branch = self.git.current_branch()
			if current_branch != None:
				node.set("branch", current_branch)
			remote_uri = self.git.current_remote_uri(branch=current_branch)
			if remote_uri != None:
				node.set("uri", remote_uri)
			else:
				node = None
		else:
			print("fatal: Not a git repository")
			node = None
				
		os.chdir(cwd)
		return node

	def __append_ignore_file(self, module):
		if os.path.exists(".gitignore"):
			ignoreFile = open(".gitignore","r")
			for line in ignoreFile:
				if module == line.strip():
					return
			ignoreFile.close()
		ignoreFile = open(".gitignore", "a")
		ignoreFile.write(module + "\n")
		ignoreFile.close()

	def __remove_ignore_file(self, modules):
		if os.path.exists(".gitignore"):
			ignoreFile = open(".gitignore","r")
			print modules
			data = [line.strip() for line in ignoreFile if not (line.strip() in modules)]
			ignoreFile = open(".gitignore", "w")
			ignoreFile.write("\n".join(data)+"\n")
			ignoreFile.close()
			data = None


	def append(self, module):
		if module == None:
			return -1
		node = self.find(module)
		root = self.tree.getroot()
		if node != None:
			root.remove(node)
		node = self.__init_module(module)
		if node == None:
			return -1
		else:
			root.append(node)
			self.__append_ignore_file(module)
		self.save()
		return 0

	def remove(self, module=None):
		if module != None:
			node = self.find(module)
			root = self.tree.getroot()
			if node != None:
				root.remove(node)
				self.__remove_ignore_file(module)
				self.save()
		else:
			data = [node.get('name') for node in self.iter()]
			self.__remove_ignore_file(data)
Esempio n. 21
0
def clone(urlStr, directory):
    git = Git(urlStr)
    git.clone(directory)
Esempio n. 22
0
 def test_tag(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     git.tag(git.latest_commit_id(), "release/1.2.3")
     tag_query = lib.call("git describe --abbrev=0 --match release/*")
     self.assertEqual(tag_query.stdout.read().strip(), "release/1.2.3")
Esempio n. 23
0
 def test_describe_never_tagged_before(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     latest_tag = git.describe()
     self.assertEqual(latest_tag, "0.0.0")
Esempio n. 24
0
 def test_clone(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     self.assertTrue(os.path.exists(os.path.join(test_repo_dir, "README.md")) == 1)
Esempio n. 25
0
 def test_describe_never_tagged_before(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     lib.call_and_exit_if_failed("git tag -a release/0.1.1 -m 'releasing version'")
     latest_tag = git.describe()
     self.assertEqual(latest_tag, "0.1.1")
Esempio n. 26
0
 def test_clone(self):
     git = Git(root_dir_local, test_repo_dir)
     git.clone()
     self.assertTrue(
         os.path.exists(os.path.join(test_repo_dir, "README.md")) == 1)