def upload(self) -> bool: """ This method executes the upload of the newest SRPM package found in the package directory. The invocation of `copr-cli` also includes the chroot settings set in the package configuration file. Returns: bool: returns *False* if anything goes wrong, *True* otherwise """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) package_dir = os.path.join(ktr.conf.get_packdir(), self.upkg.get_conf_name()) # get all srpms in the package directory srpms = glob.glob(os.path.join(package_dir, self.upkg.get_name() + "*.src.rpm")) if not srpms: logger.log("No source packages were found. Construct them first.") return False # figure out which srpm to build srpms.sort(reverse=True) srpm = srpms[0] # construct copr-cli command cmd = ["copr-cli", "build", self.get_repo()] # append chroots (dists) for dist in self.get_dists(): cmd.append("--chroot") cmd.append(dist) # append --nowait if wait=False if not self.get_wait(): cmd.append("--nowait") # append package cmd.append(srpm) # check for connectivity to server if not is_connected(self.remote): logger.log("No connection to remote host detected. Cancelling upload.", 2) return False logger.log_command(cmd, 1) subprocess.call(cmd) # TODO: error handling # remove source package if keep=False is specified if not self.get_keep(): os.remove(srpm) return True
def update(self) -> bool: """ This method executes a git repository update as specified in the package configuration file. If a specific commit has been set in the config file, this method will not attempt to execute an update. Returns: bool: *True* if update available and successful, *False* if not """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) # if specific commit is requested, do not pull updates (obviously) if self.get_commit() == "HEAD": return False # check for connectivity to server if not is_connected(self.get_orig()): logger.log("No connection to remote host detected. Cancelling source update.", 2) return False # construct git command cmd = ["git", "pull", "--rebase"] # add --verbose or --quiet depending on settings if (ktr.verby == 2) and not ktr.debug: cmd.append("--quiet") if (ktr.verby == 0) or ktr.debug: cmd.append("--verbose") # check if source directory exists before going there if not os.access(self.dest, os.W_OK): logger.err("Sources need to be get before an update can be run.") return False # get old commit ID rev_old = self.commit() # change to git repository directory prev_dir = os.getcwd() os.chdir(self.dest) # get updates logger.log_command(cmd, 1) subprocess.call(cmd) # go back to previous dir os.chdir(prev_dir) # get new commit ID rev_new = self.commit() self.date() # return True if update found, False if not return rev_new != rev_old
def get(self) -> bool: """ This method executes the download of the file specified by the URL to the package source directory. Returns: bool: *True* if successful, *False* if not or source already exists """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) # check if $KTR_BASE_DIR/sources/$PACKAGE exists and create if not if not os.access(self.sdir, os.W_OK): os.makedirs(self.sdir) # if source seems to already exist, return False if os.access(self.dest, os.R_OK): logger.log("Sources already downloaded.", 1) return False # check for connectivity to server if not is_connected(self.get_orig()): logger.log("No connection to remote host detected. Cancelling source download.", 2) return False # construct wget commands cmd = ["wget"] # add --verbose or --quiet depending on settings if (ktr.verby == 2) and not ktr.debug: cmd.append("--quiet") if (ktr.verby == 0) or ktr.debug: cmd.append("--verbose") # set origin and destination cmd.append(self.get_orig()) cmd.append("-O") cmd.append(self.dest) # wget source from origin to destination logger.log_command(cmd, 1) subprocess.call(cmd) return True
def get(self) -> bool: """ This method executes the bzr repository download to the package source directory. This respects the branch and revision set in the package configuration file. Returns: bool: `True` if successful, `False` if not or source already exists """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) # check if $KTR_BASE_DIR/sources/$PACKAGE exists and create if not if not os.access(self.sdir, os.W_OK): os.makedirs(self.sdir) # if source directory seems to already exist, return False if os.access(self.dest, os.R_OK): rev = self.rev() logger.log("Sources already downloaded. Latest revision: " + str(rev), 1) return False # check for connectivity to server if not is_connected(self.remote): logger.log("No connection to remote host detected. Cancelling source checkout.", 2) return False # construct bzr command cmd = ["bzr", "branch"] # add --verbose or --quiet depending on settings if (ktr.verby == 2) and not ktr.debug: cmd.append("--quiet") if (ktr.verby == 0) or ktr.debug: cmd.append("--verbose") # set origin if not self.get_branch(): cmd.append(self.get_orig()) else: cmd.append(self.get_orig() + "/" + self.get_branch()) # set revision is specified if self.get_revno(): cmd.append("--revision") cmd.append(self.get_revno()) # set destination cmd.append(self.dest) # branch bzr repo from origin to destination logger.log_command(cmd, 1) subprocess.call(cmd) # get commit ID rev = self.rev() # check if checkout worked if self.get_revno(): if self.get_revno() != rev: logger.err("Something went wrong, requested commit not available.") return False # return True if successful return True
def get(self) -> bool: """ This method executes the git repository download to the package source directory. This respects the branch and commit set in the package configuration file. Returns: bool: *True* if successful, *False* if not or source pre-exists """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) # check if $KTR_BASE_DIR/sources/$PACKAGE exists and create if not if not os.access(self.sdir, os.W_OK): os.makedirs(self.sdir) # if source directory seems to already exist, return False if os.access(self.dest, os.R_OK): rev = self.commit() logger.log("Sources already downloaded. Latest commit id:", 2) logger.log(rev, 2) return False # check for connectivity to server if not is_connected(self.get_orig()): logger.log("No connection to remote host detected. Cancelling source checkout.", 2) return False # construct clone command cmd_clone = ["git", "clone"] # add --verbose or --quiet depending on settings if (ktr.verby == 2) and not ktr.debug: cmd_clone.append("--quiet") if (ktr.verby == 0) or ktr.debug: cmd_clone.append("--verbose") # set --depth==1 if shallow is specified if self.get_shallow(): cmd_clone.append("--depth=1") # set branch if specified if self.get_branch(): cmd_clone.append("--branch") cmd_clone.append(self.get_branch()) # set origin and destination cmd_clone.append(self.get_orig()) cmd_clone.append(self.dest) # clone git repo from origin to destination logger.log_command(cmd_clone, 1) subprocess.call(cmd_clone) # if commit is specified: checkout commit if self.get_commit(): # construct checkout command cmd_checkout = ["git", "checkout", self.get_commit()] # go to git repo and remember old cwd prev_dir = os.getcwd() os.chdir(self.dest) # checkout commit logger.log_command(cmd_checkout, 1) subprocess.call(cmd_checkout) # go to previous dir os.chdir(prev_dir) # get commit ID rev = self.commit() self.date() # check if checkout worked if self.get_commit() != "HEAD": if self.get_commit() != rev: logger.err("Something went wrong, requested commit not checked out.") return False # return True if successful return True