From e64c353b65cbae8a1eddadf1506a6b7c85523c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Wed, 29 Jul 2020 23:18:59 +0700 Subject: [PATCH] pass-import: patch to use python3-magic Noone else ships python3-file-magic, I don't want to maintain it. --- ...s-magic-refactor-get_magics-function.patch | 55 +++++++++++++++++++ ...002-tools-magic-support-python-magic.patch | 31 +++++++++++ srcpkgs/pass-import/template | 11 +++- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 srcpkgs/pass-import/patches/0001-tools-magic-refactor-get_magics-function.patch create mode 100644 srcpkgs/pass-import/patches/0002-tools-magic-support-python-magic.patch diff --git a/srcpkgs/pass-import/patches/0001-tools-magic-refactor-get_magics-function.patch b/srcpkgs/pass-import/patches/0001-tools-magic-refactor-get_magics-function.patch new file mode 100644 index 0000000000..bd9511f391 --- /dev/null +++ b/srcpkgs/pass-import/patches/0001-tools-magic-refactor-get_magics-function.patch @@ -0,0 +1,55 @@ +From 5a1bff33c692be2fc1add61e642111976858c672 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= + +Date: Mon, 27 Jul 2020 17:31:06 +0700 +Subject: [PATCH] tools/magic: refactor get_magics function +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +In a later patch, we will add support for python-magic. +Refactore get_magics function to prepare for that change. + +Signed-off-by: Đoàn Trần Công Danh +--- + pass_import/tools.py | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git pass_import/tools.py pass_import/tools.py +index 257f01a..815ff8b 100644 +--- pass_import/tools.py ++++ pass_import/tools.py +@@ -39,20 +39,26 @@ def get_magics(path): + with open(path, 'rb') as file: + header = file.read(2048) + +- res = magic.detect_from_content(header) ++ if hasattr(magic, 'detect_from_content'): ++ res = magic.detect_from_content(header) ++ mime_type = res.mime_type ++ magic_name = res.name ++ else: ++ return None, None ++ + mime_to_format = { + 'application/pgp': 'gpg', + 'application/x-sqlite3': 'sqlite3' + } + name_to_format = {'KDBX': 'kdbx', 'openssl': 'openssl', 'PGP': 'gpg'} + +- frmt = mime_to_format.get(res.mime_type, None) ++ frmt = mime_to_format.get(mime_type, None) + for name in name_to_format: +- if name in res.name: ++ if name in magic_name: + frmt = name_to_format[name] + + encoding = None # res.encoding +- if 'UTF-8 Unicode (with BOM)' in res.name: ++ if 'UTF-8 Unicode (with BOM)' in magic_name: + encoding = 'utf-8-sig' + + return frmt, encoding +-- +2.28.0.163.g6104cc2f0b + diff --git a/srcpkgs/pass-import/patches/0002-tools-magic-support-python-magic.patch b/srcpkgs/pass-import/patches/0002-tools-magic-support-python-magic.patch new file mode 100644 index 0000000000..65b186a9d6 --- /dev/null +++ b/srcpkgs/pass-import/patches/0002-tools-magic-support-python-magic.patch @@ -0,0 +1,31 @@ +From 8cbcd2bdd885c1028065f06b7ab02673c544720b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= + +Date: Mon, 27 Jul 2020 18:00:15 +0700 +Subject: [PATCH] tools/magic: support python-magic +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Đoàn Trần Công Danh +--- + pass_import/tools.py | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git pass_import/tools.py pass_import/tools.py +index 815ff8b..c1a3f01 100644 +--- pass_import/tools.py ++++ pass_import/tools.py +@@ -43,6 +43,9 @@ def get_magics(path): + res = magic.detect_from_content(header) + mime_type = res.mime_type + magic_name = res.name ++ elif hasattr(magic, 'from_buffer'): ++ mime_type = magic.from_buffer(header, mime=True) ++ magic_name = magic.from_buffer(header) + else: + return None, None + +-- +2.28.0.163.g6104cc2f0b + diff --git a/srcpkgs/pass-import/template b/srcpkgs/pass-import/template index 758270542a..ac7590bea9 100644 --- a/srcpkgs/pass-import/template +++ b/srcpkgs/pass-import/template @@ -1,16 +1,21 @@ # Template file for 'pass-import' pkgname=pass-import version=3.0 -revision=2 +revision=3 archs=noarch build_style=gnu-makefile -make_install_args=BASHCOMPDIR=/usr/share/bash-completion/completions hostmakedepends="python3-setuptools python3-yaml" -depends="pass>=1.7.0 python3-defusedxml python3-file-magic +depends="pass>=1.7.0 python3-defusedxml python3-magic python3-cryptography python3-SecretStorage python3-pykeepass" +checkdepends="pass python3-defusedxml python3-magic python3-cryptography + python3-SecretStorage python3-pykeepass" short_desc="Pass extension for importing data from most existing password managers" maintainer="Alan Brown " license="GPL-3.0-or-later" homepage="https://github.com/roddhjav/pass-import" distfiles="https://github.com/roddhjav/pass-import/releases/download/v${version}/pass-import-${version}.tar.gz" checksum=14f6708df990b88c54b07e722686ed9e1a639300b33d2ff83dd87845e44779fc + +do_check() { + python3 setup.py test +}