Bug#934273: python3-debian: please support parsing Source: package (version)

2020-10-25 Thread David Bremner
Stuart Prescott  writes:

> Control: tags -1 patch
>
>
> In [2]: def whatmade(name, cat): 
>   ...: p = [pkg for pkg in cat if pkg['Package'] == name][0] 
>   ...: print("Source %s/%s made binary %s/%s" % ( 
>   ...: p.source, 
>   ...: p.source_version, 
>   ...: p['Package'], 
>   ...: p.get_version(), 
>   ...: )) 
>

Yes, that seems like it would work for my use case.

d



Bug#934273: python3-debian: please support parsing Source: package (version)

2020-10-24 Thread Stuart Prescott
Control: tags -1 patch

Hi David

Returning to your excellent idea in #9334273, how does the following seem? It 
adds an accessor for the the `source` and `source_version` to the classes 
generated by the deb822.Packages class:

In [1]: from debian import deb822 

In [2]: def whatmade(name, cat): 
  ...: p = [pkg for pkg in cat if pkg['Package'] == name][0] 
  ...: print("Source %s/%s made binary %s/%s" % ( 
  ...: p.source, 
  ...: p.source_version, 
  ...: p['Package'], 
  ...: p.get_version(), 
  ...: )) 

In [3]: cat = list(deb822.Packages.iter_paragraphs(open('/var/lib/apt/lists/
deb.debian.org_debian_dists_sid_main_binary-amd64_Packages'))) 

In [4]: whatmade('gcc-10', cat) 
Source gcc-10/10.2.0-15 made binary gcc-10/10.2.0-15 

In [5]: whatmade('gcc-10-base', cat) 
Source gcc-10/10.2.0-15 made binary gcc-10-base/10.2.0-15 

In [6]: whatmade('gcc', cat) 
Source gcc-defaults/1.189 made binary gcc/4:10.2.0-1 

https://salsa.debian.org/python-debian-team/python-debian/-/merge_requests/28

Does that provide the sort of API that you were hoping to have?

cheers
Stuart


-- 
Stuart Prescotthttp://www.nanonanonano.net/   stu...@nanonanonano.net
Debian Developer   http://www.debian.org/ stu...@debian.org
GPG fingerprint90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7



Bug#934273: python3-debian: please support parsing Source: package (version)

2019-08-09 Thread David Bremner
David Bremner  writes:
> def parse_source(string):
> matches=rex.match(string)
> if matches:
> return (matches.group(1),matches.group(2))
> else:
> return string

Probably return type polymorphism is a terrible idea in python. But I
guess you knew that. Maybe return (string,None) is the simplest
option. Or nicer, find the correct version from the binary package,
which I think is closer to your original idea.



Bug#934273: python3-debian: please support parsing Source: package (version)

2019-08-08 Thread David Bremner
Stuart Prescott  writes:

>
> Any opinions on whether it should return the data unparsed as
>
>   source_package (version)
>
> or whether it should be clever enough to return a 
>
>   namedtuple(..., ['source', 'version'])
>

Hmm. I'm not (blush) familiar with named tuples. I was thinking
something simple-minded like the following. By all means feel free to do
the pythonic thing though.

import re

rex=re.compile('([^(\s]+)\s*[(]([^)]+)[)]$')

def parse_source(string):
matches=rex.match(string)
if matches:
return (matches.group(1),matches.group(2))
else:
return string

def test_parse_source_without():
assert parse_source('0x') == '0x'

def test_parse_source_with():
assert parse_source('0x (0.8-1)') == ('0x','0.8-1')



Bug#934273: python3-debian: please support parsing Source: package (version)

2019-08-08 Thread Stuart Prescott
On Friday, 9 August 2019 09:42:02 AEST David Bremner wrote:
> Source: 0x (0.8-1)
> 
> is a legit line in a Packages (and buildinfo) file, we should
> impliment a parser for that once, rather than letting everyone
> re-invent their own hack.

Yes, sounds very sensible.

Since that field is also an optional one, I guess Packages should also make 
sure that it always works, providing the binary package name and binary 
package version when it is omitted.

Any opinions on whether it should return the data unparsed as

source_package (version)

or whether it should be clever enough to return a 

namedtuple(..., ['source', 'version'])


thanks for the suggestion
Stuart

-- 
Stuart Prescotthttp://www.nanonanonano.net/   stu...@nanonanonano.net
Debian Developer   http://www.debian.org/ stu...@debian.org
GPG fingerprint90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7



Bug#934273: python3-debian: please support parsing Source: package (version)

2019-08-08 Thread David Bremner
Package: python3-debian
Version: 0.1.35
Severity: wishlist

Since

Source: 0x (0.8-1)

is a legit line in a Packages (and buildinfo) file, we should
impliment a parser for that once, rather than letting everyone
re-invent their own hack.


-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'testing-debug'), (500, 
'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-5-amd64 (SMP w/8 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_CA:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages python3-debian depends on:
ii  python3  3.7.3-1
ii  python3-chardet  3.0.4-3
ii  python3-six  1.12.0-1

Versions of packages python3-debian recommends:
ii  python3-apt  1.8.4

Versions of packages python3-debian suggests:
ii  gpgv  2.2.17-3

-- no debconf information