Beispiel #1
0
    def __init__(self,
                 src: typeUnion[dict, StdPath, str],
                 profile: str = None):
        self._original = src
        if isinstance(src, dict):
            _pdata = src
        elif isinstance(src, (StdPath, str)):
            inpath = str(StdPath(src).expanduser())
            _ini = ConfigParser()
            _ini.read(inpath)
            if profile:
                _pdata = _ini._sections[profile]
            else:
                _pdata = self.get_active_profile_dict(_ini)
        else:
            raise TypeError(f"Can't process src of type: {type(src)}")

        _pdata = {k: _pdata.get(k) for k in self.VALID_ATTRIBUTES}
        super().__init__(_pdata)
        self._creds = None
Beispiel #2
0
    def upload_file(self, filename, bucket, key=None, acl="private") -> dict:
        """
        https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html

        TODO:
            - works on live server
            - test
            - handle upload_file exceptions
        """
        extra_args = {}
        extra_args["ACL"] = acl

        filepath = StdPath(filename)
        if key is None:
            key = filepath.name

        upload_response = self.client.upload_file(
            Filename=filename, Bucket=bucket, Key=key, ExtraArgs=extra_args
        )
        # at this point, upload has finished
        return self.head(bucket, key)
Beispiel #3
0
from orpyste.data import ReadBlock as READ


# ------------------- #
# -- MODULE TESTED -- #
# ------------------- #

from mistool import os_use


# ----------------------- #
# -- GENERAL CONSTANTS -- #
# ----------------------- #

THIS_DIR = StdPath(__file__).parent

PPATH_CLASS = os_use.PPath


# ----------------------- #
# -- DATAS FOR TESTING -- #
# ----------------------- #

THE_DATAS_FOR_TESTING = {}

for kind in ['good', 'bad']:
    THE_DATAS_FOR_TESTING[kind] = READ(
        content = THIS_DIR / 'depth_{0}.txt'.format(kind),
        mode    = {"keyval:: =": ":default:"}
    )
Beispiel #4
0
 def __init__(self, path: str):
     super().__init__(path)
     self._path = StdPath(self._raw_path_string)
Beispiel #5
0
 def fileext(self) -> str:
     return StdPath(self._url.path).suffix.lstrip(".")
Beispiel #6
0
 def basename(self) -> str:
     return StdPath(self._url.path).name