From 9b49ad3bb898d297922be9f20dd3c35db84ddcea Mon Sep 17 00:00:00 2001 From: Danil Suetin Date: Thu, 14 Sep 2023 16:18:44 +0700 Subject: [PATCH] python3Packages.manuf: init at 1.1.5 --- .../python-modules/manuf/default.nix | 60 +++++++++++++++++++ .../python-modules/manuf/fix_manuf_url.patch | 14 +++++ .../manuf/internal_db_update_nix.patch | 31 ++++++++++ pkgs/top-level/python-packages.nix | 2 + 4 files changed, 107 insertions(+) create mode 100644 pkgs/development/python-modules/manuf/default.nix create mode 100644 pkgs/development/python-modules/manuf/fix_manuf_url.patch create mode 100644 pkgs/development/python-modules/manuf/internal_db_update_nix.patch diff --git a/pkgs/development/python-modules/manuf/default.nix b/pkgs/development/python-modules/manuf/default.nix new file mode 100644 index 000000000000..6d237ab396fd --- /dev/null +++ b/pkgs/development/python-modules/manuf/default.nix @@ -0,0 +1,60 @@ +{ lib +, buildPythonPackage +, fetchFromGitHub +, runCommand +, python3 +, wireshark-cli +, pytestCheckHook +}: + +buildPythonPackage rec { + pname = "manuf"; + version = "1.1.5"; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "coolbho3k"; + repo = "manuf"; + rev = "${version}"; + hash = "sha256-3CFs3aqwE8rZPwU1QBqAGxNHT5jg7ymG12yBD56gTNI="; + }; + + nativeBuildInputs = [ wireshark-cli ]; + + patches = [ + # Do update while building package from wireshark-cli + ./internal_db_update_nix.patch + # Fix MANUF_URL for external db update functionality (https://github.com/coolbho3k/manuf/issues/34) + ./fix_manuf_url.patch + ]; + + postPatch = '' + cat ${wireshark-cli}/share/wireshark/{manuf,wka} > manuf/manuf + ''; + + nativeCheckInputs = [ + pytestCheckHook + ]; + + disabledTests = [ + "test_update_update" + ]; + + pythonImportsCheck = [ "manuf" ]; + + passthru.tests = { + testMacAddress = runCommand "${pname}-test" {} '' + ${python3.pkgs.manuf}/bin/manuf BC:EE:7B:00:00:00 > $out + [ "$(cat $out | tr -d '\n')" = "Vendor(manuf='ASUSTekC', manuf_long='ASUSTek COMPUTER INC.', comment=None)" ] + ''; + }; + + meta = with lib; { + homepage = "https://github.com/coolbho3k/manuf"; + description = " Parser library for Wireshark's OUI database"; + mainProgram = "manuf"; + platforms = platforms.linux; + license = with licenses; [ lgpl3Plus asl20 ]; + maintainers = with maintainers; [ dsuetin ]; + }; +} diff --git a/pkgs/development/python-modules/manuf/fix_manuf_url.patch b/pkgs/development/python-modules/manuf/fix_manuf_url.patch new file mode 100644 index 000000000000..e858649b90f2 --- /dev/null +++ b/pkgs/development/python-modules/manuf/fix_manuf_url.patch @@ -0,0 +1,14 @@ +diff --git a/manuf/manuf.py b/manuf/manuf.py +index 09e9687..0ac9296 100755 +--- a/manuf/manuf.py ++++ b/manuf/manuf.py +@@ -61,7 +61,8 @@ class MacParser(object): + IOError: If manuf file could not be found. + + """ +- MANUF_URL = "https://gitlab.com/wireshark/wireshark/raw/master/manuf" ++ # https://github.com/coolbho3k/manuf/issues/34 ++ MANUF_URL = "https://www.wireshark.org/download/automated/data/manuf" + WFA_URL = "https://gitlab.com/wireshark/wireshark/raw/master/wka" + + def __init__(self, manuf_name=None, update=False): diff --git a/pkgs/development/python-modules/manuf/internal_db_update_nix.patch b/pkgs/development/python-modules/manuf/internal_db_update_nix.patch new file mode 100644 index 000000000000..174c71e46929 --- /dev/null +++ b/pkgs/development/python-modules/manuf/internal_db_update_nix.patch @@ -0,0 +1,31 @@ +diff --git a/manuf/manuf.py b/manuf/manuf.py +index e5e9193..09e9687 100755 +--- a/manuf/manuf.py ++++ b/manuf/manuf.py +@@ -65,8 +65,14 @@ class MacParser(object): + WFA_URL = "https://gitlab.com/wireshark/wireshark/raw/master/wka" + + def __init__(self, manuf_name=None, update=False): +- self._manuf_name = manuf_name or self.get_packaged_manuf_file_path() +- if update: ++ if manuf_name is not None: ++ self._manuf_name = manuf_name ++ self.external_db = True ++ else: ++ self._manuf_name = self.get_packaged_manuf_file_path() ++ self.external_db = False ++ ++ if update and self.external_db: + self.update() + else: + self.refresh() +@@ -134,6 +140,9 @@ class MacParser(object): + URLError: If the download fails + + """ ++ if manuf_url is None and not self.external_db: ++ return ++ + if not manuf_url: + manuf_url = self.MANUF_URL + if not manuf_name: diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 01cf514cba7c..4d3f0600fd97 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -6411,6 +6411,8 @@ self: super: with self; { manuel = callPackage ../development/python-modules/manuel { }; + manuf = callPackage ../development/python-modules/manuf { }; + mapbox = callPackage ../development/python-modules/mapbox { }; mapbox-earcut = callPackage ../development/python-modules/mapbox-earcut { };