Skip to content

Commit

Permalink
feature: implement tar.gz support
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Sep 1, 2023
1 parent f8496d4 commit 172c30f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions ckanext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# this is a namespace package
try:
import pkg_resources

pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil

__path__ = pkgutil.extend_path(__path__, __name__)
3 changes: 1 addition & 2 deletions ckanext/unfold/adapters/_7z.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import py7zr
from py7zr import FileInfo, exceptions

import ckanext.unfold.utils as unf_utils
import ckanext.unfold.types as unf_types

import ckanext.unfold.utils as unf_utils

log = logging.getLogger(__name__)

Expand Down
7 changes: 5 additions & 2 deletions ckanext/unfold/adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from . import rar, _7z, zip, gzip, tar
from functools import partial

from . import _7z, gzip, rar, tar, zip

ADAPTERS = {
"rar": rar.build_directory_tree,
Expand All @@ -7,5 +9,6 @@
"zip": zip.build_directory_tree,
"gz": gzip.build_directory_tree,
"gzip": gzip.build_directory_tree,
"tar": tar.build_directory_tree
"tar": partial(tar.build_directory_tree),
"tar.gz": partial(tar.build_directory_tree, gz=True),
}
1 change: 1 addition & 0 deletions ckanext/unfold/adapters/gzip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from ckan import model as model

import ckanext.unfold.types as unf_types


Expand Down
5 changes: 3 additions & 2 deletions ckanext/unfold/adapters/rar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import logging

import rarfile
from rarfile import RarInfo, Error as RarError
from rarfile import Error as RarError
from rarfile import RarInfo

import ckanext.unfold.utils as unf_utils
import ckanext.unfold.types as unf_types
import ckanext.unfold.utils as unf_utils

log = logging.getLogger(__name__)

Expand Down
9 changes: 4 additions & 5 deletions ckanext/unfold/adapters/tar.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from __future__ import annotations

import logging

import tarfile
from tarfile import TarInfo, TarError
from tarfile import TarError, TarInfo

import ckanext.unfold.utils as unf_utils
import ckanext.unfold.types as unf_types
import ckanext.unfold.utils as unf_utils

log = logging.getLogger(__name__)


def build_directory_tree(filepath: str):
def build_directory_tree(filepath: str, gz: bool = False):
try:
with tarfile.TarFile(filepath) as archive:
with tarfile.open(filepath, "r:gz" if gz else "r") as archive:
file_list: list[TarInfo] = archive.getmembers()
except TarError as e:
log.error(f"Error openning rar archive: {e}")
Expand Down
4 changes: 2 additions & 2 deletions ckanext/unfold/adapters/zip.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import logging
from zipfile import ZipFile, ZipInfo, LargeZipFile, BadZipFile
from zipfile import BadZipFile, LargeZipFile, ZipFile, ZipInfo

import ckanext.unfold.utils as unf_utils
import ckanext.unfold.types as unf_types
import ckanext.unfold.utils as unf_utils

log = logging.getLogger(__name__)

Expand Down
8 changes: 3 additions & 5 deletions ckanext/unfold/helpers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from __future__ import annotations

import logging
import json

import requests
from requests.exceptions import RequestException

import logging
from typing import Any

import ckan.lib.uploader as uploader
import requests
from requests.exceptions import RequestException

import ckanext.unfold.adapters as unf_adapters
import ckanext.unfold.types as unf_types
Expand Down
1 change: 0 additions & 1 deletion ckanext/unfold/logic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from ckan.logic.schema import validator_args


Schema = Dict[str, Any]


Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# message extraction at
# http://babel.pocoo.org/docs/messages/#extraction-method-mapping-and-configuration
message_extractors={
'ckanext': [
('**.py', 'python', None),
('**.js', 'javascript', None),
('**/templates/**.html', 'ckan', None),
"ckanext": [
("**.py", "python", None),
("**.js", "javascript", None),
("**/templates/**.html", "ckan", None),
],
}
)

0 comments on commit 172c30f

Please sign in to comment.