1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-21 17:56:19 +02:00
Commit Graph

106 Commits

Author SHA1 Message Date
lethliel
5841bf759f add exception if encoding fails and try ISO-8859-1
In some rare cases the chardet encoding detection detects
a wrong encoding standard. Then we switch to latin-1 which
covers most if utf-8 does not work.
2019-04-16 14:40:13 +02:00
Marco Strigl
71770555ac
Merge pull request #526 from lethliel/python3_fix_debquery_decoding
[python3] fix decoding issue in debquery.py
2019-04-15 15:10:21 +02:00
Marco Strigl
6c074fce20
Merge pull request #524 from lethliel/python3_packagequery_fix_decoding
[python3] fix decoding for packageqeury.py
2019-04-15 15:09:59 +02:00
Marco Strigl
41ced89fcc
Merge pull request #522 from lethliel/python3_repodata_module
[python3] fix epoch encoding in repodata.py
2019-04-15 15:07:50 +02:00
Marco Strigl
0086bcfa64
Merge pull request #483 from lethliel/python3_rpmquery_module
[python3] rpmquery.py now python3 ready
2019-04-15 15:02:59 +02:00
Marco Strigl
d5108c7536
Merge pull request #464 from lethliel/python3_utils_helper
[python3] add helper functions for python3 support
2019-04-15 15:00:58 +02:00
lethliel
60c6ec2b52 [python3] fix decoding issue in debquery.py
name, version, release and arch are strings, not bytes
2019-04-07 14:44:25 -05:00
lethliel
c235148180 [python3] now python3 ready:
* new function cmp (not available in python3)
  * fix decoding in canonname function
2019-04-07 11:05:13 -05:00
lethliel
c6d3870942 [python3] fix decoding for packageqeury.py
name, arch, version and release need to be decoded
2019-04-07 10:31:23 -05:00
lethliel
87628a4150 [python3] fix epoch encoding in repodata.py
other.epoch() needs to be encoded to work with the vercmp callers.
2019-04-07 10:19:47 -05:00
Marcus Huewe
c534d7e990 Fix logic error in DebQuery.vercmp
res is never None, because DebQuery.rpmvercmp always returns -1, 0,
or 1.
2019-01-27 19:43:38 +01:00
Marcus Huewe
cd5f46984d Port debquery module to python3
No functional changes. Note that we cannot simply decode the control's
fields as ascii/utf-8 because a field is not necessarily a valid
ascii/utf-8 encoding (it is possible to register _arbitrary_ custom
fields via a 'register-custom-fields' hook when building a deb
package).

Note: DebQuery.debvercmp really deserves a cleanup:/
2019-01-27 19:31:47 +01:00
Marcus Huewe
bb9f9a7fde Refactor DebQuery.__parse_control a bit
No functional changes. This just simplifies the upcoming python3
port a bit.
2019-01-27 17:35:47 +01:00
Marcus Huewe
f63a0957af Remove superfluous try-except block in the archquery module
ArchQuery.query never raises an ArchError exception.
2019-01-27 16:51:58 +01:00
Marcus Huewe
2074a1c01d Make ArchQuery.canonname more robust against None values
Use ArchQuery.filename to construct the filename and raise an
ArchError exception if we are unable to construct a filename.
2019-01-27 16:46:52 +01:00
Marcus Huewe
8c1cb190bd Port the missing pieces of the archquery module to python3
This is a follow-up commit for commit
21eca9e3f1 ("[python3] switch
ArchQuery to bytestrings").
2019-01-27 16:27:30 +01:00
Marcus Huewe
2d0c974296 Add cmp function to packagequery module
cmp(a, b) returns
-1 if a < b
 0 if a == 0
 1 if a > b

This is needed since python3 has no cmp function anymore.

All credits for this go to Marco Strigl <mstrigl@suse.com> (see
PR#483 [1]).

[1] https://github.com/openSUSE/osc/pull/483
2019-01-27 16:12:57 +01:00
Marcus Huewe
a3720c5286 Fix ArchQuery.rpmvercmp if one of its arguments is None
The None argument is always <= than the other argument. We need this
in case of a broken/pathological package where version() or release()
return None (see vercmp (which calls rpmvercmp)).
2019-01-27 15:50:35 +01:00
Marcus Huewe
5c639db805 ArchQuery.epoch should never return None
Returning None breaks ArchQuery.vercmp. Returning b'0' is ok because
an epoch, if present, is always supposed to be an integer (at least
in a "valid" arch package (see scripts/libmakepkg/lint_pkgbuild/epoch.sh.in
in the pacman sources)). Hence, if we compare the epoch of a package,
which has no explicit epoch set, with the epoch of a package, which
has an explicit epoch set, we always have a <= relation.
2019-01-27 15:39:07 +01:00
Marcus Huewe
deee8ef6cb Fix logic error in ArchQuery.vercmp
res is never None, because ArchQuery.rpmvercmp always returns -1, 0,
or 1.
2019-01-27 15:00:36 +01:00
Marcus Huewe
562374f045 Simplify ArchQuery.read a bit
No functional changes - just to improve readability.
2019-01-27 14:57:47 +01:00
Marcus Huewe
e580769757 Merge branch 'python3_archquery_module' of https://github.com/lethliel/osc
Initial port of the archquery module to python3 (ArchQuery.__init__,
ArchQuery.read, and ArchQuery.canonname are ported - the rest is missing).
2019-01-27 14:55:01 +01:00
lethliel
21eca9e3f1 [python3] switch ArchQuery to bytestrings
decode explicit (ascii)
2019-01-23 22:59:55 +01:00
Marco Strigl
f233066448
Merge pull request #482 from lethliel/python3_packagequery_module
[python3] magic is now a bytestring in python3
2019-01-18 14:34:43 +01:00
Marcus Huewe
e60af6f120 Use with statement in CpioRead._copyin_file
This makes sure that the file is closed in case of an exception.
2019-01-15 20:49:26 +01:00
Marcus Huewe
5387744d36 Port CpioWrite to python3
Now, CpioWrite provides a bytes-only API. It would be also possible
that the API accepts bytes and str (we would need to explicitly
encode the latter) but this would be a bit inconsistent wrt.
cpio.CpioRead (which is bytes-only).
Also, by using a bytesarray instead of a [] we avoid several
intermediate ''.join(...)s.
2019-01-15 20:48:42 +01:00
Marcus Huewe
3e326b1bb4 Port CpioRead and CpioHdr to python3
This is a bytes only API because a filename in a cpio archive can
contain, for instance, illegal utf-8 sequences. A user can decode
the filename/content as she wishes.
2019-01-15 20:05:47 +01:00
Marcus Huewe
54ac438eb0 Do not mmap a cpio archive
There is simply no need for a mmap.
2019-01-15 19:47:27 +01:00
Marcus Huewe
1c4385a579 Run a small demo when the cpio module is invoked as a script
It just reads in a cpio archive and print the headers.
2019-01-15 19:46:00 +01:00
Marcus Huewe
5c19425c9b Use with statement in ArFile.saveTo
This makes sure that the file is closed in case of an exception.
2019-01-15 17:18:50 +01:00
Marcus Huewe
b26a4a967d Raise a ValueError if neither fn nor fh is passed to Ar.__init__
A ValueError is more appropriate because there is no issue with the
ar archive itself. Also, the old codepath never worked because the
fn parameter was missing.
2019-01-15 17:18:50 +01:00
Marcus Huewe
6fdce86fc9 Port the ar module to python3
Since an ar archive can contain arbitary filenames (that is a
filename can be an invalid utf-8 encoding (for instance,
"foo\xff\xffbar")), the ar module provides a bytes only API. A
user can decode filenames as she wishes.
Note: if a "fn" parameter is passed to Ar.__init__ it should be a
bytes (a str is also ok, but then be aware that an ArError's file
attribute might be a str or a bytes).
2019-01-15 17:18:37 +01:00
Marcus Huewe
68cf974c78 Do not mmap the ar archive
There is really no need for a mmap here. Also, the comment in the
docstr does not apply/is nonsense (there is no performance gain).
2019-01-15 17:18:19 +01:00
Marcus Huewe
e12181b11d An ext fn header in an ar file has no mode
Use a dummy mode of 0 in this case (internally, the mode is never
used).
2019-01-15 17:18:19 +01:00
Marcus Huewe
2e45edbe16 Remove superfluous StopIteration exception from the ar module
There is no need to raise a StopIteration exception.
2019-01-15 17:18:19 +01:00
Marcus Huewe
470b187374 Run a small demo when the ar module is invoked as a script
It just prints the ar headers.
2019-01-15 17:18:10 +01:00
Marcus Huewe
28eeff8683 Simplify rpmquery.unpack_string
There is no need to unpack a single byte because it is not
affected by (byte) endianness (and that's what struct.unpack is
about). Moreover, rpmquery.unpack_string now supports an optional
encoding parameter, which could be used by the python3 port to
decode a string. Note: in general we cannot assume that all strings
in a rpm are utf-8 encoded (it is possible to build a rpm that
contains illegal utf-8 sequences).
2019-01-14 16:40:09 +01:00
lethliel
2d5a3aeb3b [python3] magic is now a bytestring in python3 2018-12-13 13:23:26 +01:00
Fridrich Štrba
89cef1f8c1 Do not choke on operators < and > in spec files 2018-11-28 10:55:17 +01:00
lethliel
4b29e1c543 add helper functions for python3 support
This functions are used in the whole code and are
mandatory for the python3 support to work. In python2
case nothing is touched.

* cmp_to_key:
  converts a cmp= into a key= function

* decode_list:
  decodes each element of a list. This is needed if
  we have a mixed list with strings and bytes.

* decode_it:
  Takes the input and checks if it is not a string.
  Then it uses chardet to get the encoding.
2018-11-08 09:55:07 +01:00
lethliel
9ffe9b9288 improve error message if file is not a valid rpm
The current error message is quite confusing and nobody knows what
"invalid lead magic" means.
2018-10-09 10:16:27 +02:00
lethliel
779b66f3c3 fixed indentation of return[].
It works in python2, but will break in python3
2018-07-06 09:54:59 +02:00
Marcus Huewe
caaefb0bf5 Fix and simplify util.safewriter.SafeWriter
Storing the error encoding in an "encoding" attribute "breaks" the
python3 "input" function: In essence, builtin_input_impl does a
getattr(sys.stdout, 'encoding'), which returns our error encoding
instead of the "real" stdout encoding. In order to avoid this, we
store the error encoding in an "_encoding" attribute.

Making SafeWriter a new-style class simplifies the code a lot.
2018-03-09 16:55:56 +01:00
Marcus Huewe
ebb2f2ee0d Add support for querying weak dependencies
The following abstract methods are added to the PackageQueryResult
class: recommends(), suggests(), supplements(), and enhances().
Note that not all package/metadata formats have a notion of these
weak dependencies.

              rpm   rpmmd   deb   arch
recommends     x      x      x
suggests       x      x      x     x
supplements    x      x
enhances       x      x      x

(where "x" represents "supported"). In case of an unsupported weak
dependency, the implementation returns an empty list.

We need the weak dependency support in order to fix #363 ("osc build
-p ../rpms/tw doesnt send recommends to the server which makes client
side build behave differently to server side build").
2017-12-26 23:14:47 +01:00
Riku Voipio
9166a7f075 debquery: support control.tar.xz
Similar to recent fixes in libsolv and obs-build. Since tarfile
on python2 doesn't do lzma, decompress the file into memory and
feed it as a fake file via StringIO to tarfile
2017-10-30 14:10:54 +02:00
Andreas Schwab
9f00759e02 Support arm packages in pkg-prefer 2016-08-08 10:35:14 +02:00
Marcus Huewe
fa4f24f06b - RpmQuery.rpmvercmp: support tilde ('~') 2015-07-03 14:22:00 +02:00
Daniel Gollub
64838ffd51 Support native Debian packages in pkg-prefer
fixes #158
2015-07-02 15:08:39 +02:00
Marcus Huewe
a80b286ac9 - fixed #147
Introduced new PackageQueryResult class and adapted existing
modules accordingly.
2015-06-23 17:52:37 +02:00
Michael Schroeder
7acaba2d8a add obsoletes, conflicts, evr query methods 2014-12-09 13:04:55 +01:00