Ejemplo n.º 1
0
 def test_cost_assignment(self):
     r = hawkey.Repo("fog", cost=500)
     self.assertEqual(500, r.cost)
     r.cost = 300
     self.assertEqual(300, r.cost)
     r2 = hawkey.Repo("blizzard")
     self.assertEqual(1000, r2.cost)
Ejemplo n.º 2
0
    def test_cost_assignment(self):
        r = hawkey.Repo("fog")
        r.cost = 300
        self.assertEqual(300, r.cost)

        r2 = hawkey.Repo("blizzard")
        self.assertEqual(1000, r2.cost)
        with self.assertRaises(TypeError):
            r2.cost = '4'
Ejemplo n.º 3
0
def get_repo(repo_dir, repo_descriptor, download=False):
    """
    Obtain hawkey Repo either by loading from disk, or downloading from
    Koji.

    :repo_dir: path to directory where the repo is/should be stored
    :repo_descriptor: which repo to obtain
    :download: whether to download or load locally
    """
    h = librepo.Handle()
    repo_path = os.path.join(repo_dir, str(repo_descriptor))
    if download:
        h.destdir = repo_path
        shutil.rmtree(repo_path, ignore_errors=True)
        os.makedirs(os.path.join(repo_path, 'cache'))
    h.repotype = librepo.LR_YUMREPO
    h.urls = [repo_descriptor.url if download else repo_path]
    h.local = not download
    h.yumdlist = ['primary', 'filelists', 'group', 'group_gz']
    result = librepo.Result()
    try:
        result = h.perform(result)
    except librepo.LibrepoException as e:
        if e.args[0] == librepo.LRE_NOURL:
            return None
        raise
    repodata = result.yum_repo
    repo = hawkey.Repo(str(repo_descriptor))
    repo.repomd_fn = repodata['repomd']
    repo.primary_fn = repodata['primary']
    repo.filelists_fn = repodata['filelists']
    return repo
Ejemplo n.º 4
0
def add_repo_to_sack(repoid, repo_result, sack):
    repodata = repo_result.yum_repo
    repo = hawkey.Repo(repoid)
    repo.repomd_fn = repodata['repomd']
    repo.primary_fn = repodata['primary']
    repo.filelists_fn = repodata['filelists']
    sack.load_yum_repo(repo, load_filelists=True)
Ejemplo n.º 5
0
 def create(self, repo_id, repo_dir):
     """ Load repo from disk into memory as sack """
     if not repo_dir:
         return None
     try:
         sack = hawkey.Sack(arch=self._for_arch)
         for arch in self._arches:
             log.debug('Loading repo {} for arch {} from disk into memory'.
                       format(repo_id, arch))
             arch_repo_dir = os.path.join(repo_dir, arch)
             h = librepo.Handle()
             h.local = True
             h.repotype = librepo.LR_YUMREPO
             h.urls = [arch_repo_dir]
             h.yumdlist = ['primary', 'filelists', 'group']
             repodata = h.perform(librepo.Result()).yum_repo
             repo = hawkey.Repo('{}-{}'.format(repo_id, arch))
             repo.repomd_fn = repodata['repomd']
             repo.primary_fn = repodata['primary']
             repo.filelists_fn = repodata['filelists']
             sack.load_yum_repo(repo, load_filelists=True)
         log.debug('Repo {} successfully loaded into memory'.format(repo_id))
         return sack
     except (librepo.LibrepoException, IOError):
         log.debug('Repo {} could not be loaded'.format(repo_id))
         return None
Ejemplo n.º 6
0
    def download_rpms(self):
        repodata_dir = os.path.join(self.photon_root, 'RPMS/repodata')
        process = subprocess.Popen(['mkdir', '-p', repodata_dir], stdout=self.output)
        retval = process.wait()

        import hawkey
        self.install_factor = 1
        # Load the repo data
        sack = hawkey.Sack()
        
        repomd_filename = "repomd.xml"
        repomd_url = os.path.join(self.rpm_path, "repodata/repomd.xml")

        self.download_file(repomd_url, repodata_dir)

        # parse to the xml to get the primary and files list
        tree = ET.parse(os.path.join(repodata_dir, repomd_filename))
        # TODO: Get the namespace dynamically from the xml file
        ns = {'ns': 'http://linux.duke.edu/metadata/repo'}

        primary_location = tree.find("./ns:data[@type='primary']/ns:location", ns).get("href");
        filelists_location = tree.find("./ns:data[@type='filelists']/ns:location", ns).get("href");
        primary_filename = os.path.basename(primary_location);
        filelists_filename = os.path.basename(filelists_location);

        self.download_file(os.path.join(self.rpm_path, primary_location), repodata_dir)
        self.download_file(os.path.join(self.rpm_path, filelists_location), repodata_dir)
        
        repo = hawkey.Repo("installrepo")
        repo.repomd_fn = os.path.join(repodata_dir, repomd_filename)
        repo.primary_fn = os.path.join(repodata_dir, primary_filename)
        repo.filelists_fn = os.path.join(repodata_dir, filelists_filename)
        
        sack.load_yum_repo(repo, load_filelists=True)

        progressbar_num_items = 0
        self.rpms_tobeinstalled = []
        selected_packages = self.install_config['packages']
        for package in selected_packages:
            # Locate the package
            q = hawkey.Query(sack).filter(name=package)
            if (len(q) > 0):
                progressbar_num_items +=  q[0].size + q[0].size * self.install_factor
                self.rpms_tobeinstalled.append({'package': package, 'size': q[0].size, 'location': q[0].location, 'filename': os.path.basename(q[0].location)})
            else:
                print >> sys.stderr, "Package %s not found in the repo" % package
                #self.exit_gracefully(None, None)

        self.progress_bar.update_num_items(progressbar_num_items)

        # Download the rpms
        for rpm in self.rpms_tobeinstalled:
            message = 'Downloading {0}...'.format(rpm['filename'])
            self.progress_bar.update_message(message)
            self.download_file(os.path.join(self.rpm_path, rpm['location']), os.path.join(self.photon_root, "RPMS"))
            self.progress_bar.increment(rpm['size'])
        
        # update the rpms path
        self.rpm_path = os.path.join(self.photon_root, "RPMS")
Ejemplo n.º 7
0
def get_repo_mock(repo_dir, descriptor, download=False):
    if 'copr' in str(type(descriptor)).lower():
        repo = hawkey.Repo(str(descriptor))
        path = os.path.join(testdir, 'repos', 'copr_repo', 'repodata')
        repo.repomd_fn = os.path.join(path, 'repomd.xml')
        repo.primary_fn = os.path.join(path, 'primary.xml')
        repo.filelists_fn = os.path.join(path, 'filelists.xml')
        return repo
    return get_repo(repo_dir, descriptor, download)
Ejemplo n.º 8
0
def _get_hawkey_sack(repo_info):
    hk_repo = hawkey.Repo("")
    hk_repo.filelists_fn = repo_info["filelists"]
    hk_repo.primary_fn = repo_info["primary"]
    hk_repo.repomd_fn = repo_info["repomd"]

    primary_sack = hawkey.Sack()
    primary_sack.load_repo(hk_repo, build_cache=False)

    return primary_sack
Ejemplo n.º 9
0
def _get_hawkey_sack(repo_info):
    """
    A function to pull in the repository sack from hawkey.
    Returns the sack.
    """
    hk_repo = hawkey.Repo("")
    hk_repo.filelists_fn = repo_info["filelists"]
    hk_repo.primary_fn = repo_info["primary"]
    hk_repo.repomd_fn = repo_info["repomd"]

    primary_sack = hawkey.Sack()
    primary_sack.load_repo(hk_repo, build_cache=False)

    return primary_sack
Ejemplo n.º 10
0
def get_sack():
    # hawkey sacks cannot be easily populated from within python and mocking
    # hawkey queries would be too complicated, therefore using real repos
    h = librepo.Handle()
    h.local = True
    h.repotype = librepo.LR_YUMREPO
    h.urls = ['repo']
    h.yumdlist = ['primary']
    repodata = h.perform(librepo.Result()).yum_repo
    repo = hawkey.Repo('test')
    repo.repomd_fn = repodata['repomd']
    repo.primary_fn = repodata['primary']
    sack = hawkey.Sack(arch='x86_64')
    sack.load_yum_repo(repo)
    return sack
Ejemplo n.º 11
0
    def __init__(self, *args):
        support.TestCase.__init__(self, *args)
        self.base = support.MockBase()
        self.sack = self.base.sack

        # load the testing repo
        repo = support.MockRepo('drpm', '/tmp/dnf-cache')
        self.base.repos[repo.id] = repo
        repo.baseurl = ['file://%s/%s' % (support.repo_dir(), repo.id)]
        repo.load()

        # add it to sack
        hrepo = hawkey.Repo(repo.id)
        hrepo.repomd_fn = repo.repomd_fn
        hrepo.primary_fn = repo.primary_fn
        hrepo.filelists_fn = repo.filelists_fn
        hrepo.presto_fn = repo.presto_fn
        self.sack.load_yum_repo(hrepo, load_filelists=True, load_presto=True)
Ejemplo n.º 12
0
 def _load_sack(self, repo_descriptor, repo_path, build_cache=False):
     """ Load repo from disk into memory as sack. """
     cache_dir = os.path.join(repo_path, 'cache')
     for_arch = get_config('dependency.resolve_for_arch')
     if build_cache:
         os.mkdir(cache_dir)
     sack = hawkey.Sack(arch=for_arch, cachedir=cache_dir)
     h = librepo.Handle()
     h.local = True
     # pylint:disable=no-member
     h.repotype = librepo.LR_YUMREPO
     h.urls = [repo_path]
     h.yumdlist = ['primary', 'filelists', 'group']
     repodata = h.perform(librepo.Result()).yum_repo
     repo = hawkey.Repo(str(repo_descriptor))
     repo.repomd_fn = repodata['repomd']
     repo.primary_fn = repodata['primary']
     repo.filelists_fn = repodata['filelists']
     sack.load_yum_repo(repo, load_filelists=True, build_cache=build_cache)
     return sack
Ejemplo n.º 13
0
def fetch_repo(repo, base_path=None, cache_ttl=3600):
    """
    Fetch remote metadata for a list of Repos into {base_path}/{repo.url hash}/
    and return a hawkey.Repo configured with local repodata.

    :param repo: RPM repository to fetch (Repo named tuple)
    :param base_path: a base path to store local repodata cache in
    :param cache_ttl: time to live for local repodata cache (0 to disable)
    :return: hawkey.Repo pointing to local repodata ready to be loaded
    """
    if not base_path:
        base_path = helpers.get_default_cache_base_path()
    repodata_url = "%s/repodata" % repo.url
    repo_path = os.path.join(base_path, helpers.repo_dir(repo.id, repo.url))
    log.info("Fetching %s into %s", repodata_url, repo_path)
    helpers.ensure_dir(repo_path)
    # fetch remote repodata files
    repomd = helpers.cached_remote_fetch(repo_path,
                                         repodata_url,
                                         'repomd.xml',
                                         cache_ttl=cache_ttl,
                                         return_data=True)
    primary_fn, filelists_fn = parse_repomd(repomd)
    helpers.cached_remote_fetch(repo_path,
                                repodata_url,
                                primary_fn,
                                cache_ttl=cache_ttl)
    helpers.cached_remote_fetch(repo_path,
                                repodata_url,
                                filelists_fn,
                                cache_ttl=cache_ttl)
    # consturct hawkey.Repo pointing to local metadata
    hrepo = hawkey.Repo(repo.id)
    hrepo.repomd_fn = os.path.join(repo_path, 'repomd.xml')
    hrepo.primary_fn = os.path.join(repo_path, primary_fn)
    hrepo.filelists_fn = os.path.join(repo_path, filelists_fn)
    return hrepo
Ejemplo n.º 14
0
            if not got_link:
                print('Unable to find link')
                sys.exit(1)

            h.setopt(librepo.LRO_REPOTYPE, librepo.LR_YUMREPO)
            h.setopt(librepo.LRO_CHECKSUM, True)
            h.setopt(librepo.LRO_PROGRESSCB, dl_callback)
            h.setopt(librepo.LRO_YUMDLIST, ["group", "primary"])
            h.setopt(librepo.LRO_INTERRUPTIBLE, True)
            h.perform(r)
            repo_info = r.getinfo(librepo.LRR_YUM_REPO)

            # Get primary
            primary_sack = hawkey.Sack()
            hk_repo = hawkey.Repo(repo)
            hk_repo.repomd_fn = repo_info['repomd']
            hk_repo.primary_fn = repo_info['primary']
            primary_sack.load_repo(hk_repo, load_filelists=False)

            # Get comps
            comps = libcomps.Comps()
            if 'group' in repo_info:
                ret = comps.fromxml_f(repo_info['group'])
                if ret == -1:
                    print('Error parsing')
                    break

            repos[repo] = (comps, primary_sack)

    expanded = 0
Ejemplo n.º 15
0
 def test_failed_load(self):
     sack = hawkey.Sack(cachedir=base.cachedir)
     repo = hawkey.Repo("name")
     self.assertRaises(IOError, sack.load_repo, repo)
     sack = hawkey.Sack()
Ejemplo n.º 16
0
 def as_hawkey_repo(self):
     repo = hawkey.Repo(self.name)
     repo.repomd_fn = self.repomd_fn
     repo.primary_fn = self.primary_fn
     repo.filelists_fn = self.filelists_fn
     return repo
Ejemplo n.º 17
0
 def test_str_assignment(self):
     r = hawkey.Repo('fog')
     with self.assertRaises(TypeError):
         r.repomd_fn = 3
     r.repomd_fn = 'rain'
     self.assertEqual(r.repomd_fn, 'rain')
Ejemplo n.º 18
0
 def test_create(self):
     r = hawkey.Repo("fog")
     self.assertIsNotNone(r)
     self.assertRaises(TypeError, hawkey.Repo)
     self.assertRaises(TypeError, hawkey.Repo, 3)
     self.assertRaises(TypeError, hawkey.Repo, rain="pouring")
Ejemplo n.º 19
0
import librepo

op_name = sys.argv[1]
if sys.argv[1] != "list":
    pkg_name = sys.argv[2]

# Librepo Configurations
MAIN_REPO = "/home/thejdeep/test_repo/"
DESTDIR = "/home/thejdeep/test_repo/repodata/"
PROGRESSBAR_LEN = 40
finished = False

# Hawkey Configurations
sack = hawkey.Sack()
path = "/home/thejdeep/test_repo/repodata/%s"
repo = hawkey.Repo("test")
repo.repomd_fn = path % "repomd.xml"
repo.primary_fn = path % "b6f6911f7d9fb63f001388f1ecd0766cec060c1d04c703c6a74969eadc24ec97-primary.xml.gz"
repo.filelists_fn = path % "df5897ed6d3f87f2be4432543edf2f58996e5c9e6a7acee054f9dbfe513df4da-filelists.xml.gz"
sack.load_repo(repo, load_filelists=True)
#sack.load_system_repo()

# Functions start


def callback(data, total_to_download, downloaded):
    """Progress callback"""
    global finished

    if total_to_download != downloaded:
        finished = False
Ejemplo n.º 20
0
 def _init_hawkey_repo(self):
     hrepo = hawkey.Repo(self.id)
     hrepo.cost = self.cost
     hrepo.priority = self.priority
     return hrepo
Ejemplo n.º 21
0
 def get_hawkey_repo(reponame, repoinfo):
     repo = hawkey.Repo(reponame)
     repo.repomd_fn = repoinfo['repomd']
     repo.primary_fn = repoinfo['primary']
     repo.filelists_fn = repoinfo['filelists']
     return repo