Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1062180 - [api] dnf.conf.Conf.cachedir doesn't have a default value
Summary: [api] dnf.conf.Conf.cachedir doesn't have a default value
Keywords:
Status: CLOSED DUPLICATE of bug 1184943
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf
Version: 20
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Michal Luscon
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 1066869
TreeView+ depends on / blocked
 
Reported: 2014-02-06 12:10 UTC by Kamil Páral
Modified: 2015-01-29 14:25 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-01-29 14:25:49 UTC


Attachments (Terms of Use)

Description Kamil Páral 2014-02-06 12:10:58 UTC
Description of problem:
The docs say:

cachedir

    Path to a directory used by various DNF subsystems for storing cache data. Has a reasonable root-writable default depending on the distribution. It is up to the client to set this to a location where files and directories can be created under the running user. The directory can be safely deleted after the dnf.Base object is destroyed

http://akozumpl.github.io/dnf/api_conf.html#dnf.conf.Conf.cachedir

However, the doesn't seem to be any reasonable default value set:

In [1]:

import dnf

import dnf.repo

In [2]:

base = dnf.Base()

In [3]:

repos = base.repos

In [4]:

repo = dnf.repo.Repo('local repo',None)

In [5]:

repo.baseurl='file:///home/kparal/tmp/repo'

In [6]:

print repo

[None]
ip_resolve: None
proxy_password: None
includepkgs: []
bandwidth: 0
cost: 1000
http_caching: 'all'
exclude: []
keepalive: True
repo_gpgcheck: False
sslverify: True
failovermethod: 'roundrobin'
gpgkey: []
fastestmirror: False
mirrorlist: None
gpgcheck: False
sslcacert: None
username: None
metadata_expire: 172800
sslclientcert: None
baseurl: ['file:///home/kparal/tmp/repo']
gpgcakey: []
proxy: None
throttle: 0
password: None
retries: 10
mediaid: None
name: None
sslclientkey: None
metalink: None
enabled: True
skip_if_unavailable: True
proxy_username: None
timeout: 30.0
enablegroups: True

In [7]:

repos.add(repo)

In [8]:

print base.repos

{'local repo': <Repo local repo>}

In [9]:

base.fill_sack(load_system_repo=False)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-7f6a05b3c53f> in <module>()
----> 1 base.fill_sack(load_system_repo=False)

/usr/lib/python2.7/site-packages/dnf/base.pyc in fill_sack(self, load_system_repo, load_available_repos)
    210             if load_available_repos:
    211                 for r in self.repos.iter_enabled():
--> 212                     self._add_repo_to_sack(r.id)
    213         conf = self.conf
    214         self._sack.configure(conf.installonlypkgs, conf.installonly_limit)

/usr/lib/python2.7/site-packages/dnf/base.pyc in _add_repo_to_sack(self, name)
    118         repo = self.repos[name]
    119         try:
--> 120             repo.load()
    121         except dnf.exceptions.RepoError as e:
    122             if repo.skip_if_unavailable is False:

/usr/lib/python2.7/site-packages/dnf/repo.pyc in load(self)
    434 
    435         """
--> 436         if self.metadata or self._try_cache():
    437             if self.sync_strategy == SYNC_ONLY_CACHE or not self.metadata.expired:
    438                 logger.debug('repo: using cache for: %s' % self.id)

/usr/lib/python2.7/site-packages/dnf/repo.pyc in _try_cache(self)
    296         """
    297         assert(self.metadata is None)
--> 298         handle = self._handle_new_local(self.cachedir)
    299         try:
    300             self.metadata = self._handle_load(handle)

/usr/lib/python2.7/site-packages/dnf/repo.pyc in cachedir(self)
    344     @property
    345     def cachedir(self):
--> 346         return os.path.join(self.basecachedir, self.id)
    347 
    348     _REPOCONF_ATTRS = set(dir(dnf.yum.config.RepoConf))

/usr/lib64/python2.7/posixpath.pyc in join(a, *p)
     75         if b.startswith('/'):
     76             path = b
---> 77         elif path == '' or path.endswith('/'):
     78             path +=  b
     79         else:

AttributeError: 'NoneType' object has no attribute 'endswith'


Version-Release number of selected component (if applicable):
dnf-0.4.12-1.fc20.noarch

How reproducible:
always

Comment 1 Kamil Páral 2014-02-06 12:16:40 UTC
I need to set a cachedir for both base and repo objects to get rid of the error. Like this:

base.conf.cachedir = '/var/tmp/kparal-dnf'
repo = dnf.repo.Repo('local repo','/var/tmp/kparal-dnf')

If I set just the first one, the same error occurs. If I set only the second one, the error is different:

IOError                                   Traceback (most recent call last)
<ipython-input-71-7f6a05b3c53f> in <module>()
----> 1 base.fill_sack(load_system_repo=False)

/usr/lib/python2.7/site-packages/dnf/base.pyc in fill_sack(self, load_system_repo, load_available_repos)
    210             if load_available_repos:
    211                 for r in self.repos.iter_enabled():
--> 212                     self._add_repo_to_sack(r.id)
    213         conf = self.conf
    214         self._sack.configure(conf.installonlypkgs, conf.installonly_limit)

/usr/lib/python2.7/site-packages/dnf/base.pyc in _add_repo_to_sack(self, name)
    134             self.logger.debug("not found deltainfo for: %s" % repo.name)
    135         repo.hawkey_repo = hrepo
--> 136         self._sack.load_yum_repo(hrepo, build_cache=True, load_filelists=True)
    137 
    138     def _setup_excludes(self):

IOError: Can not read repomd file.

Comment 2 Ales Kozumplik 2014-02-06 16:53:28 UTC
this is an underspecified API feature. we will fix that (by providing the default probably)

Comment 3 Tim Lauridsen 2014-03-24 12:19:18 UTC
The current implementation need the following code to setup the cache when running as non-root. It will setup the cache dir to the same as the dnf cli does

base = dnf.Base()
base.conf.releasever = None # This will take the current release
suffix = dnf.yum.parser.varReplace(dnf.const.CACHEDIR_SUFFIX, conf.yumvar)
cli_cache = dnf.conf.CliCache(conf.cachedir, suffix)
base.conf.cachedir = cli_cache.cachedir
base._system_cachedir = cli_cache.system_cachedir

sure it wil get more simple in some future realease of dnf :)

Comment 4 Michal Luscon 2014-12-09 11:15:39 UTC
Hi,

in the current upstream version of dnf the base config contains default value of cachedir, so you can use it in the following way:

base = dnf.Base()
repos = base.repos
repo = dnf.repo.Repo('local repo', base.conf.cachedir)
repo.baseurl='file:///home/kparal/tmp/repo'
repos.add(repo)
base.fill_sack(load_system_repo=False)

I have also extended cachedir_fit() with intention to use it for retrieving the dnf user and system cachedir:

user_cachedir, system_cachedir = dnf.cli.cli.cachedir_fit(base.conf)

Comment 5 Radek Holy 2014-12-09 12:11:45 UTC
Just a minor correction:

(In reply to Michal Luscon from comment #4)
> repo.baseurl='file:///home/kparal/tmp/repo'
According to the documentation, "baseurl" should be a list of strings.

Comment 6 Michal Luscon 2015-01-29 14:25:49 UTC

*** This bug has been marked as a duplicate of bug 1184943 ***


Note You need to log in before you can comment on or make changes to this bug.