def __load_repo_metadata(self, repo_url): from dulwich import porcelain subdir = get_repo_subdir(repo_url) repo_dir = os.path.join(self.__beq_dir, subdir) commit_url = get_commit_url(repo_url) try: with porcelain.open_repo_closing(repo_dir) as local_repo: last_commit = local_repo[local_repo.head()] last_commit_time_utc = last_commit.commit_time last_commit_qdt = QDateTime() last_commit_qdt.setTime_t(last_commit_time_utc) self.lastCommitDate.setDateTime(last_commit_qdt) from datetime import datetime import calendar d = datetime.utcnow() now_utc = calendar.timegm(d.utctimetuple()) days_since_commit = (now_utc - last_commit_time_utc) / 60 / 60 / 24 warning_msg = '' if days_since_commit > 7.0: warning_msg = f" was {round(days_since_commit)} days ago, press the button to update -->" commit_link = f"{commit_url}/{last_commit.id.decode('utf-8')}" self.infoLabel.setText(f"<a href=\"{commit_link}\">Last Commit</a>{warning_msg}") self.infoLabel.setTextFormat(Qt.RichText) self.infoLabel.setTextInteractionFlags(Qt.TextBrowserInteraction) self.infoLabel.setOpenExternalLinks(True) self.lastCommitMessage.setPlainText( f"Author: {last_commit.author.decode('utf-8')}\n\n{last_commit.message.decode('utf-8')}") except: logger.exception(f"Unable to open git repo in {self.__beq_dir}") self.__beq_dir_not_exists(repo_url)
def update_beq_repo_status(self, repo_url): ''' updates the displayed state of the selected beq repo ''' subdir = get_repo_subdir(repo_url) if os.path.exists(self.__beq_dir) and os.path.exists(os.path.join(self.__beq_dir, subdir, '.git')): self.__load_repo_metadata(repo_url) else: self.__beq_dir_not_exists(repo_url)
def __beq_dir_not_exists(self, repo_url): target_path = os.path.abspath(os.path.join(self.__beq_dir, get_repo_subdir(repo_url))) self.infoLabel.setText( f"BEQ repo not found in {target_path}, press the button to clone the repository -->") self.lastCommitMessage.clear() time = QDateTime() time.setMSecsSinceEpoch(0) self.lastCommitDate.setDateTime(time)
def update_beq_count(self): git_files = 0 user_files = 0 for repo_url in self.__beq_repos: subdir = get_repo_subdir(repo_url) if os.path.exists(self.__beq_dir) and os.path.exists(os.path.join(self.__beq_dir, subdir, '.git')): git_files += len(glob.glob(f"{self.__beq_dir}{os.sep}{subdir}{os.sep}**{os.sep}*.xml", recursive=True)) if len(self.userSourceDir.text().strip()) > 0 and os.path.exists(self.userSourceDir.text()): user_files = len(glob.glob(f"{self.userSourceDir.text()}{os.sep}**{os.sep}*.xml", recursive=True)) if user_files > 0 or git_files > 0: self.__show_or_hide(git_files > 0, user_files > 0) self.totalFiles.setValue(user_files + git_files)
def __populate_catalogue(self, repo_url): subdir = get_repo_subdir(repo_url) if os.path.exists(self.__beq_dir) and os.path.exists( os.path.join(self.__beq_dir, subdir, '.git')): search_path = f"{self.__beq_dir}{os.sep}{subdir}{os.sep}**{os.sep}*.xml" beqs = sorted(filter(lambda x: x.name is not None, [ BEQ(subdir, x) for x in glob.glob(search_path, recursive=True) ]), key=lambda x: x.name) for name, grouped in groupby(beqs, lambda x: x.name): beq_list = list(grouped) for beq in beq_list: k = self.__make_key(beq) if len(beq_list) > 1 else beq.name if k in self.__catalogue: logger.warning( f"Duplicate catalogue entry found at {beq.filename} vs {self.__catalogue[k]}" ) else: self.__catalogue[k] = beq