Details
Details
- Reviewers
kparal - Commits
- rLTRNb07ff282c553: D148 - Fixes for @kparal's comments + D151
unittests work
Diff Detail
Diff Detail
- Repository
- rLTRN libtaskotron
- Lint
Lint Skipped - Unit
Unit Tests Skipped
kparal |
unittests work
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | libtaskotron/koji_utils.py (15 lines) |
Commit | Tree | Parents | Author | Summary | Date |
---|---|---|---|---|---|
eff6c335b8a4 | c5d3b46733a8 | b420fe644aea | Josef Skladanka | D148 - Fixes for @kparal's comments + D151 (Show More…) | Jun 23 2014, 1:22 PM |
Show All 18 Lines | |||||
19 | from libtaskotron import config | 19 | from libtaskotron import config | ||
20 | 20 | | |||
21 | 21 | | |||
22 | class KojiClient(object): | 22 | class KojiClient(object): | ||
23 | '''Helper Koji methods. | 23 | '''Helper Koji methods. | ||
24 | 24 | | |||
25 | :ivar koji.ClientSession session: Koji client session | 25 | :ivar koji.ClientSession session: Koji client session | ||
26 | ''' | 26 | ''' | ||
27 | | ||||
27 | def __init__(self, koji_session=None): | 28 | def __init__(self, koji_session=None): | ||
28 | '''Create a new KojiClient | 29 | '''Create a new KojiClient | ||
29 | 30 | | |||
30 | :param koji_session: an existing Koji session instance or ``None`` if | 31 | :param koji_session: an existing Koji session instance or ``None`` if | ||
31 | you want a new default session to be created | 32 | you want a new default session to be created | ||
32 | :type koji_session: :class:`koji.ClientSession` | 33 | :type koji_session: :class:`koji.ClientSession` | ||
33 | ''' | 34 | ''' | ||
34 | self.session = (koji_session or | 35 | self.session = (koji_session or | ||
35 | koji.ClientSession(config.get_config().koji_url)) | 36 | koji.ClientSession(config.get_config().koji_url)) | ||
37 | | ||||
38 | # contains a rpm_filename -> build info mapping used in rpm_to_build | ||||
36 | self._rpm_to_build_cache = {} | 39 | self._rpm_to_build_cache = {} | ||
37 | 40 | | |||
41 | | ||||
38 | def rpm_to_build(self, rpm, prefetch=True): | 42 | def rpm_to_build(self, rpm, prefetch=True): | ||
39 | '''Get koji build object for the rpm. | 43 | '''Get koji build object for the rpm. | ||
40 | 44 | | |||
41 | :param str rpm: filename as either `/my/path/nvr.a.rpm` or `nvr.a.rpm` | 45 | :param str rpm: filename as either ``/my/path/nvr.a.rpm`` or ``nvr.a.rpm`` | ||
42 | :param bool prefetch: if set to True, get list of all rpms for the build | 46 | :param bool prefetch: if set to True, get list of all rpms for the build | ||
43 | and store it for future use - this will speed up subsequent queries | 47 | and store it for future use - this will speed up subsequent queries | ||
44 | for rpms belonging to already queried build. | 48 | for rpms belonging to already queried build. | ||
45 | :rtype: bunch | 49 | :return: Koji buildinfo dictionary (as returned e.g. from :meth:`koji.getBuild`) | ||
46 | :raise TaskotronRemoteError: if rpm or build is not found in koji | 50 | :rtype: :class:`bunch.Bunch` | ||
51 | :raise TaskotronRemoteError: if rpm or it's related build is not found | ||||
47 | ''' | 52 | ''' | ||
53 | | ||||
54 | # extract filename from the (possible) path | ||||
48 | rpm = os.path.split(rpm)[-1] | 55 | rpm = os.path.split(rpm)[-1] | ||
49 | 56 | | |||
50 | if rpm in self._rpm_to_build_cache: | 57 | if rpm in self._rpm_to_build_cache: | ||
51 | return self._rpm_to_build_cache[rpm] | 58 | return self._rpm_to_build_cache[rpm] | ||
52 | 59 | | |||
53 | rpminfo = self.session.getRPM(rpm) | 60 | rpminfo = self.session.getRPM(rpm) | ||
54 | if rpminfo is None: | 61 | if rpminfo is None: | ||
55 | raise exc.TaskotronRemoteError('RPM not found') | 62 | raise exc.TaskotronRemoteError('RPM not found') | ||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 141 | if not os.path.isdir(rpm_dir): | |||
135 | raise exc.TaskotronRemoteError( | 142 | raise exc.TaskotronRemoteError( | ||
136 | "Can't create directory: %r It is an already " | 143 | "Can't create directory: %r It is an already " | ||
137 | "existing file.", rpm_dir) | 144 | "existing file.", rpm_dir) | ||
138 | else: | 145 | else: | ||
139 | try: | 146 | try: | ||
140 | file_utils.makedirs(rpm_dir) | 147 | file_utils.makedirs(rpm_dir) | ||
141 | except OSError, e: | 148 | except OSError, e: | ||
142 | log.exception("Can't create directory: %s", rpm_dir) | 149 | log.exception("Can't create directory: %s", rpm_dir) | ||
143 | raise TaskotronRemoteError(e) | 150 | raise exc.TaskotronRemoteError(e) | ||
144 | 151 | | |||
145 | 152 | | |||
146 | rpm_urls = self.nvr_to_urls(nvr, | 153 | rpm_urls = self.nvr_to_urls(nvr, | ||
147 | arches=arches, | 154 | arches=arches, | ||
148 | debuginfo=debuginfo, | 155 | debuginfo=debuginfo, | ||
149 | src=src) | 156 | src=src) | ||
150 | rpm_files = [] | 157 | rpm_files = [] | ||
151 | log.info('Fetching %s RPMs for: %s', len(rpm_urls), nvr) | 158 | log.info('Fetching %s RPMs for: %s', len(rpm_urls), nvr) | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |
its :-)