def test_log(self): logger = LoggerMock() hl = Hardlink(logger=logger) log_level = 1 message = "foobar" hl.log(log_level, message) self.assertEqual(logger.loglvl, log_level) self.assertEqual(logger.msg, message)
def test_link(self): path_src = os.path.join(self.tmp_dir, "a") open(path_src, 'w').write("asdf") path_dst = os.path.join(self.tmp_dir, "b") hl = Hardlink() hl.link(path_src, path_dst) self.assertEqual(os.stat(path_src), os.stat(path_dst))
def copyout(self, pkg_list, input_path, output_path): """Copy out packages from repository but only those name is in list. Creates hardlinks instead of new copies. @param pkg_list: list of pakckage names to copy @type comps: list @param input_path: input path @type input_path: str @param output_path: output path @type output_path: str """ _hardlink = Hardlink(test=False) self.logger.debug("copyout input:%s output:%s" % (input_path, output_path)) copied = set() for pkg in pkg_list: for file_name in glob.glob( os.path.join(input_path, pkg) + "*.rpm"): if not kobo.rpmlib.parse_nvra( os.path.basename(file_name))["name"] == pkg: continue # not the exact package name copied.add(pkg) _hardlink(file_name, output_path) return copied
def download_extras(self, cache_path, path, urls): """Downloads extra RPMs into a repo @param cache_path: extras cache path @type cache_path: str @param path: output path @type path: str @param urls: list of URLs to download @type urls: list """ _hardlink = Hardlink(test=False) if not os.path.exists(cache_path): os.makedirs(cache_path) for url in urls: self.logger.info("downloading %s" % url) basename = os.path.basename(url) cache_file = os.path.join(cache_path, basename) cmd = "/usr/bin/wget -nc -O %s %s" % (cache_file, url) self.logger.debug("running %s" % cmd) status, output = kobo.shortcuts.run(cmd, can_fail=True) for line in output.splitlines(): self.logger.debug("extras wget: %s" % line) _hardlink(cache_file, os.path.join(path, basename))