def git_checkout_repo(dst_path, what): gitdir = os.path.join(dst_path, ".git") cmd = [ "git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "checkout", what ] runcmd(cmd) return GitCmd(dst_path)
def git_log_repo(repo_path, max_depth, since_date): gitdir = os.path.join(repo_path, ".git") cmd = [ "git", "--git-dir=%s" % gitdir, "--work-tree=%s" % repo_path, "log", "--pretty=format:%H:%an <%ae>:%at:%s" ] if max_depth: cmd.append("--max-count=%d" % max_depth) if since_date: cmd.append("--since=%s" % since_date) stdout, stderr, rt = runcmd(cmd) if rt != 0: raise RuntimeError("Failed to run git log --pretty: %s", stderr) lines = stdout.split('\n') ret = [] for line in lines: if line == "": continue # skip no results # hash: author name <e-mail>:time:subject m = re.match("([A-Fa-f0-9]+):(.*):([0-9]+):(.*)", line) ret.append({ 'hash': m.group(1), 'author': m.group(2), 'time': m.group(3), 'commit': m.group(4) }) return ret
def license_analysis(self, file_id): ''' Analyse a file for licenses @param file_id: a file id of a file that needs to be analysed @return: list of all licenses found ''' ret = ServiceResult() self.tmpfile_path = self.get_tmp_filename() with self.get_system() as system: f = system.download(file_id, self.tmpfile_path) self.extracted1_path = self.get_tmp_dirname() d = f.unpack(self.extracted1_path) if isinstance(d, ExtractedRpmFile): src_path = d.get_content_path() elif isinstance(d, ExtractedTarballFile): src_path = d.get_path() elif isinstance(d, ExtractedSrpmFile): # we have to unpack tarball first t = d.get_tarball() self.extracted2_path = self.get_tmp_dirname() d = f.unpack(self.extracted2_path) src_path = d.get_path() else: raise ValueError("Filetype %s cannot be processed" % (d.get_type(),)) stdout, stderr, _ = runcmd(["licenselib/cucos_license_check.py", src_path]) ret.result = json.loads(stdout) ret.meta['stderr'] = stderr ret.meta['tool'] = "cucos_license_check" return ret
def git_log_repo(repo_path, max_depth, since_date): gitdir = os.path.join(repo_path, ".git") cmd = ["git", "--git-dir=%s" % gitdir, "--work-tree=%s" % repo_path, "log", "--pretty=format:%H:%an <%ae>:%at:%s"] if max_depth: cmd.append("--max-count=%d" % max_depth) if since_date: cmd.append("--since=%s" % since_date) stdout, stderr, rt = runcmd(cmd) if rt != 0: raise RuntimeError("Failed to run git log --pretty: %s", stderr) lines = stdout.split('\n') ret = [] for line in lines: if line == "": continue # skip no results # hash: author name <e-mail>:time:subject m = re.match("([A-Fa-f0-9]+):(.*):([0-9]+):(.*)", line) ret.append({ 'hash': m.group(1), 'author': m.group(2), 'time': m.group(3), 'commit': m.group(4) }) return ret
def _git_tree_prepare(self, package_name, branch, commit=None): path = os.path.join(self.pkg_dir, package_name) if not os.path.isdir(path): runcmd(['fedpkg', 'clone', '-a', package_name], cwd=self.pkg_dir) self._register_pkg(package_name) path = os.path.join(self.pkg_dir, package_name) repo = gitapi.Repo(path) repo.git_checkout(branch) if commit is not None: repo.git_checkout(commit) else: repo.git_pull() self._mark_used(package_name) return path
def git_pull_repo(dst_path): gitdir = os.path.join(dst_path, ".git") cmd = [ "git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "pull" ] stdout, stderr, rt = runcmd(cmd) return stdout
def git_rev_parse_head_repo(dst_path): gitdir = os.path.join(dst_path, ".git") cmd = [ "git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "rev-parse", "HEAD" ] stdout, stderr, rt = runcmd(cmd) return stdout
def _git_tree_prepare(self, package_name, branch, commit=None): path = os.path.join(self.pkg_dir, package_name) if not os.path.isdir(path): runcmd(["fedpkg", "clone", "-a", package_name], cwd=self.pkg_dir) self._register_pkg(package_name) path = os.path.join(self.pkg_dir, package_name) repo = gitapi.Repo(path) repo.git_checkout(branch) if commit is not None: repo.git_checkout(commit) else: repo.git_pull() self._mark_used(package_name) return path
def license_analysis(self, file_id): ''' Analyse a file for licenses @param file_id: a file id of a file that needs to be analysed @return: list of all licenses found ''' ret = ServiceResult() self.tmpfile_path = self.get_tmp_filename() with self.get_system() as system: f = system.download(file_id, self.tmpfile_path) self.extracted1_path = self.get_tmp_dirname() d = f.unpack(self.extracted1_path) if isinstance(d, ExtractedRpmFile): src_path = d.get_content_path() elif isinstance(d, ExtractedTarballFile): src_path = d.get_path() elif isinstance(d, ExtractedSrpmFile): # we have to unpack tarball first t = d.get_tarball() self.extracted2_path = self.get_tmp_dirname() d = f.unpack(self.extracted2_path) src_path = d.get_path() else: raise ValueError("Filetype %s cannot be processed" % (d.get_type(), )) stdout, stderr, _ = runcmd( ["licenselib/cucos_license_check.py", src_path]) ret.result = json.loads(stdout) ret.meta['stderr'] = stderr ret.meta['tool'] = "cucos_license_check" return ret
def git_clone_repo(url, dst_path): cmd = ["git", "clone", url, dst_path] runcmd(cmd) return GitCmd(dst_path)
def git_pull_repo(dst_path): gitdir = os.path.join(dst_path, ".git") cmd = ["git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "pull"] stdout, stderr, rt = runcmd(cmd) return stdout
def git_rev_parse_head_repo(dst_path): gitdir = os.path.join(dst_path, ".git") cmd = ["git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "rev-parse", "HEAD"] stdout, stderr, rt = runcmd(cmd) return stdout
def git_checkout_repo(dst_path, what): gitdir = os.path.join(dst_path, ".git") cmd = ["git", "--git-dir=%s" % gitdir, "--work-tree=%s" % dst_path, "checkout", what] runcmd(cmd) return GitCmd(dst_path)