~martijnbraam/public-inbox

shipments: get_tracking_info: Don't try to guess the carrier when already provided v1 APPLIED

~dos: 2
 get_tracking_info: Don't try to guess the carrier when already provided
 on_carrier_change: Fix display name handling

 3 files changed, 26 insertions(+), 11 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~martijnbraam/public-inbox/patches/26853/mbox | git am -3
Learn more about email & git

[PATCH shipments 1/2] get_tracking_info: Don't try to guess the carrier when already provided Export this patch

From: Sebastian Krzyszkowiak <dos@dosowisko.net>

---
 shipments/__init__.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/shipments/__init__.py b/shipments/__init__.py
index 61f61b8..219c45d 100644
--- a/shipments/__init__.py
+++ b/shipments/__init__.py
@@ -15,16 +15,19 @@ def identify_tracking(code):
def get_tracking_info(code, extra=None, carrier=None):
    options = []
    extra = extra if extra is not None else []
    for c in get_carriers():
        definition = getattr(carriers, c)
        if definition.identify(code):
            options.append(definition())

    if len(options) == 0:
        return None
    elif len(options) > 1:
        return False
    instance = options[0]
    if not carrier:
        for c in get_carriers():
            definition = getattr(carriers, c)
            if definition.identify(code):
                options.append(definition())

        if len(options) == 0:
            return None
        elif len(options) > 1:
            return False
        instance = options[0]
    else:
        instance = get_carrier(carrier)

    return instance.get_info(code, extra)

-- 
2.32.0

[PATCH shipments 2/2] on_carrier_change: Fix display name handling Export this patch

From: Sebastian Krzyszkowiak <dos@dosowisko.net>

---
 shipments/__init__.py   | 12 ++++++++++++
 shipments_gtk/window.py |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/shipments/__init__.py b/shipments/__init__.py
index 219c45d..4133b3a 100644
--- a/shipments/__init__.py
+++ b/shipments/__init__.py
@@ -50,3 +50,15 @@ def get_carriers():
            continue
        result[cn] = cls.DISPLAYNAME
    return result

def get_carrier_code_for_display_name(display_name):
    for cn, cls in carriers.__dict__.items():
        if cn.startswith('__'):
            continue
        if cn == 'Carrier':
            continue
        if not hasattr(cls, 'DISPLAYNAME'):
            continue
        if cls.DISPLAYNAME == display_name:
            return cn
    return None
diff --git a/shipments_gtk/window.py b/shipments_gtk/window.py
index eaf85d9..52f133f 100644
--- a/shipments_gtk/window.py
+++ b/shipments_gtk/window.py
@@ -77,7 +77,7 @@ class NewPackageDialog(Gtk.Dialog):
        for child in self.extrabox:
            self.extrabox.remove(child)

        carrier = shipments.get_carrier(self.carrier.get_active_text())
        carrier = shipments.get_carrier(shipments.get_carrier_code_for_display_name(self.carrier.get_active_text()))

        extra_data = carrier.get_requirements(self.code.get_text())
        for fieldname, fieldlabel, fieldtype in extra_data:
-- 
2.32.0