def __init__(self, config=None, keep_version=False, offline=False, user_config=None): ConfigObject.__init__(self, config=config) self.user_config = user_config self.full_project_dir = os.getcwd() self.spec_file_name = find_spec_like_file() self.project_name = get_project_name(tag=None) self.relative_project_dir = get_relative_project_dir_cwd( self.git_root) # i.e. java/ self.spec_file = os.path.join(self.full_project_dir, self.spec_file_name) self.keep_version = keep_version self.today = self._changelog_date() (self.git_user, self.git_email) = get_git_user_info() git_email = self.git_email if git_email is None: git_email = '' self.changelog_regex = re.compile('\\*\s%s\s%s(\s<%s>)?' % (self.today, self.git_user, git_email.replace("+", "\+").replace(".", "\."))) self._no_auto_changelog = False self._accept_auto_changelog = False self._new_changelog_msg = "new package built with tito" self._changelog = None self.offline = offline
def _get_build_version(self): """ Figure out the git tag and version-release we're building. """ # Determine which package version we should build: build_version = None if self.build_tag: build_version = self.build_tag[len(self.project_name + "-"):] else: build_version = get_latest_tagged_version(self.project_name) if build_version is None: if not self.test: error_out(["Unable to lookup latest package info.", "Perhaps you need to tag first?"]) warn_out("unable to lookup latest package " "tag, building untagged test project") build_version = get_spec_version_and_release(self.start_dir, find_spec_like_file(self.start_dir)) self.build_tag = "%s-%s" % (self.project_name, build_version) self.spec_version = build_version.split('-')[-2] self.spec_release = build_version.split('-')[-1] if not self.test: check_tag_exists(self.build_tag, offline=self.offline) return build_version
def _setup_sources(self): """ Create a copy of the git source for the project at the point in time our build tag was created. Created in the temporary rpmbuild SOURCES directory. """ self._create_build_dirs() debug("Creating %s from git tag: %s..." % (self.tgz_filename, self.git_commit_id)) create_tgz(self.git_root, self.tgz_dir, self.git_commit_id, self.relative_project_dir, os.path.join(self.rpmbuild_sourcedir, self.tgz_filename)) # Extract the source so we can get at the spec file, etc. debug("Copying git source to: %s" % self.rpmbuild_gitcopy) run_command("cd %s/ && tar xzf %s" % (self.rpmbuild_sourcedir, self.tgz_filename)) # Show contents of the directory structure we just extracted. debug('', 'ls -lR %s/' % self.rpmbuild_gitcopy) # NOTE: The spec file we actually use is the one exported by git # archive into the temp build directory. This is done so we can # modify the version/release on the fly when building test rpms # that use a git SHA1 for their version. self.spec_file_name = os.path.basename(find_spec_like_file(self.rpmbuild_gitcopy)) self.spec_file = os.path.join( self.rpmbuild_gitcopy, self.spec_file_name)
def __init__(self, config=None, keep_version=False, offline=False, user_config=None): ConfigObject.__init__(self, config=config) self.user_config = user_config self.full_project_dir = os.getcwd() self.spec_file_name = find_spec_like_file() self.project_name = get_project_name(tag=None) self.relative_project_dir = get_relative_project_dir_cwd( self.git_root) # i.e. java/ self.spec_file = os.path.join(self.full_project_dir, self.spec_file_name) self.keep_version = keep_version self.today = strftime("%a %b %d %Y") (self.git_user, self.git_email) = self._get_git_user_info() git_email = self.git_email if git_email is None: git_email = '' self.changelog_regex = re.compile('\\*\s%s\s%s(\s<%s>)?' % (self.today, self.git_user, git_email.replace("+", "\+").replace(".", "\."))) self._no_auto_changelog = False self._accept_auto_changelog = False self._new_changelog_msg = "new package built with tito" self._changelog = None self.offline = offline
def _get_build_version(self): self.spec_version = '' self.spec_release = '' build_version = get_spec_version_and_release( self.start_dir, find_spec_like_file(self.start_dir)) self.build_tag = build_version return build_version
def __init__(self, config=None, keep_version=False, offline=False, user_config=None): super(RestraintVersionTagger, self).__init__(config, keep_version, offline, user_config) fedora_spec_file_name = find_spec_like_file( os.path.join(os.getcwd(), 'specfiles/')) self.fedora_spec_file = os.path.join(self.full_project_dir, 'specfiles/', fedora_spec_file_name)
def _get_build_version(self): """ Figure out the git tag and version-release we're building. """ # Determine which package version we should build: build_version = None if self.build_tag: build_version = self.build_tag[len(self.project_name + "-"):] else: build_version = get_spec_version_and_release( self.start_dir, find_spec_like_file(self.start_dir)) self.build_tag = self._get_tag_for_version(build_version) self.spec_version = build_version.split('-')[0] self.spec_release = build_version.split('-')[-1] return build_version
def test_find_spec_like_file_spec(self, mock_find): mock_find.side_effect = ["result.spec"] result = find_spec_like_file() self.assertEquals("result.spec", result) self.assertEquals(1, len(mock_find.mock_calls))
def test_find_spec_like_file_tmpl(self, mock_find): mock_find.side_effect = [None, "result.spec.tmpl"] result = find_spec_like_file() self.assertEquals("result.spec.tmpl", result) self.assertEquals(2, len(mock_find.mock_calls))
def _setup_sources(self): """ Create a copy of the git source for the project at the point in time our build tag was created. Created in the temporary rpmbuild SOURCES directory. """ self._create_build_dirs() working_path = os.path.join(os.getcwd(), self.relative_project_dir) debug('SETUP SOURCES') if self.relative_project_dir in os.path.join(os.getcwd(), ''): working_path = os.getcwd() debug("working_path: %s" % working_path) for directory, _, filenames in os.walk(working_path): debug('WALK') dir_artifacts_with_path = [ os.path.join(directory, f) for f in filenames ] debug(dir_artifacts_with_path) for artifact in dir_artifacts_with_path: debug(" Copying source file %s" % artifact) if os.path.isfile(artifact): if not os.path.exists("/".join( [self.rpmbuild_gitcopy, os.path.basename(artifact)])): shutil.copy(artifact, self.rpmbuild_gitcopy) if not os.path.exists("/".join( [self.rpmbuild_sourcedir, os.path.basename(artifact)])): shutil.copy(artifact, self.rpmbuild_sourcedir) # NOTE: The spec file we actually use is the one exported by git # archive into the temp build directory. This is done so we can # modify the version/release on the fly when building test rpms # that use a git SHA1 for their version. self.spec_file_name = os.path.basename( find_spec_like_file(self.rpmbuild_sourcedir)) self.spec_file = os.path.join(self.rpmbuild_sourcedir, self.spec_file_name) self.old_cwd = os.getcwd() # pylint: disable=W0201 if self.relative_project_dir not in os.path.join(os.getcwd(), ''): os.chdir(os.path.join(self.old_cwd, self.relative_project_dir)) # NOTE: 'which' may not be installed... (docker containers) status = getstatusoutput("which git-annex")[0] if status != 0: msg = "Please run '%s' as root." % self.package_manager.install( ["git-annex"]) error_out('%s' % msg) run_command("git-annex lock") annexed_files = run_command( "git-annex find --include='*'").splitlines() run_command("git-annex get") run_command("git-annex unlock") debug(" Annex files: %s" % annexed_files) for annex in annexed_files: debug("Copying unlocked file %s" % annex) if os.path.isfile(os.path.join(self.rpmbuild_gitcopy, annex)): os.remove(os.path.join(self.rpmbuild_gitcopy, annex)) shutil.copy(annex, self.rpmbuild_gitcopy) self._lock() os.chdir(self.old_cwd)