From ca72080f21950dedb0f174f07af923b14ca20863 Mon Sep 17 00:00:00 2001 From: dvm-shlee Date: Sat, 1 Jul 2023 16:42:10 -0400 Subject: [PATCH 1/2] python classifier removed for publishing to pypi --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index a3efb83..2494c6e 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,6 @@ 'Intended Audience :: Science/Research', 'Topic :: Scientific/Engineering :: Medical Science Apps.', 'Natural Language :: English', - 'Programming Language :: Python :: >3.5' ], keywords = 'bruker data_handler converter administrator_tool' ) From 76f9554650388e1e463128f9de8715c55c025693 Mon Sep 17 00:00:00 2001 From: dvm-shlee Date: Sat, 1 Jul 2023 16:55:14 -0400 Subject: [PATCH 2/2] remove 'shleeh' dependency and release 0.3.8 --- .gitignore | 3 +- brkraw/__init__.py | 2 +- brkraw/lib/backup.py | 6 +- brkraw/lib/errors.py | 125 +++++++++++++++++++++++++++++++++++++++ brkraw/lib/loader.py | 11 +++- brkraw/lib/utils.py | 17 +++++- brkraw/scripts/brkraw.py | 4 +- setup.py | 3 +- 8 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 brkraw/lib/errors.py diff --git a/.gitignore b/.gitignore index 66435fc..98c5b69 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ build test test/* *.egg-info -*.egg-info/* \ No newline at end of file +*.egg-info/* +.DS_Store \ No newline at end of file diff --git a/brkraw/__init__.py b/brkraw/__init__.py index a39e7da..acfe095 100644 --- a/brkraw/__init__.py +++ b/brkraw/__init__.py @@ -1,6 +1,6 @@ from .lib import * -__version__ = '0.3.8-rc1' +__version__ = '0.3.8' __all__ = ['BrukerLoader', '__version__'] diff --git a/brkraw/lib/backup.py b/brkraw/lib/backup.py index d5ba587..214775b 100644 --- a/brkraw/lib/backup.py +++ b/brkraw/lib/backup.py @@ -1,8 +1,6 @@ -from shleeh import * -from shleeh.utils import * -from shleeh.errors import * +from .errors import * from .loader import BrukerLoader -from .utils import get_dirsize, get_filesize, yes_or_no +from .utils import get_dirsize, get_filesize, yes_or_no, TimeCounter import os import sys import tqdm diff --git a/brkraw/lib/errors.py b/brkraw/lib/errors.py new file mode 100644 index 0000000..81d3572 --- /dev/null +++ b/brkraw/lib/errors.py @@ -0,0 +1,125 @@ +import os + + +def print_internal_error(io_handler=None): + import traceback + import sys + if io_handler is None: + io_handler = sys.stderr + traceback.print_exception(*sys.exc_info(), + file=io_handler) + + +class Error(Exception): + """ Base class for other custom exceptions """ + message = None + + +class FileNotValidError(Error): + """ Raised when the file is not valid format """ + + def __init__(self, file_name=None, data_type=None): + self.file_name = None + self.data_type = None + + if file_name is not None: + self.file_name = os.path.basename(file_name) + if os.path.isdir(file_name): + object_type = 'directory' + else: + object_type = 'file' + if data_type is not None: + self.data_type = data_type + self.message = "The {} '{}' is not valid {}".format(object_type, + self.file_name, + self.data_type) + else: + self.message = "The {} '{}' is not valid".format(object_type, + self.file_name) + else: + self.message = "The file is not valid" + + +class ArchiveFailedError(Error): + """ Raised when the archive process is failed [designed for brkraw module] """ + file_name = None + + def __init__(self, file_name=None): + if file_name is not None: + self.file_name = os.path.basename(file_name) + self.message = "The data '{}' is not archived".format( + self.file_name) + else: + self.message = "Archive failed to execute" + + +class RemoveFailedError(Error): + """ Raise when the os.remove process is failed """ + file_name = None + + def __init__(self, file_name=None): + if file_name is not None: + self.file_name = os.path.basename(file_name) + self.message = "The file '{}' is not removed".format( + self.file_name) + else: + self.message = "Remove failed to execute" + + +class RenameFailedError(Error): + """ Raised when the os.rename process is failed (OSError)""" + file1_name = None + file2_name = None + + def __init__(self, file1_name=None, file2_name=None): + if file1_name is not None: + self.file1_name = os.path.basename(file1_name) + if file2_name is not None: + self.file2_name = os.path.basename(file2_name) + if (self.file1_name is not None) and (self.file2_name is not None): + self.message = "Rename failed to execute from:'{}' to:'{}'".format(self.file1_name, + self.file2_name) + else: + self.message = "Rename failed to execute" + + +class UnexpectedError(Error): + """ Raised when unexpected error occurred """ + + def __init__(self, message=None): + print_internal_error() + if message is None: + self.message = "Unexpected error" + else: + self.message = message + + +class ValueConflictInField(Error): + """ Raised when input value was conflicted with other """ + + def __init__(self, message=None): + if message is None: + self.message = "The value is conflicted" + else: + self.message = message + + +class InvalidValueInField(Error): + """ Raise when the invalid value is detected in field """ + + def __init__(self, message=None): + if message is None: + self.message = "Invalid value is detected" + else: + self.message = message + + +class InvalidApproach(Error): + """ Raise when the user try invalid approach """ + + def __init__(self, message=None): + print_internal_error() + if message is None: + self.message = "Invalid approach!" + else: + self.message = message diff --git a/brkraw/lib/loader.py b/brkraw/lib/loader.py index 9502a49..961602f 100644 --- a/brkraw/lib/loader.py +++ b/brkraw/lib/loader.py @@ -1,6 +1,4 @@ -from shleeh import * -from shleeh.errors import * - +from .errors import * from .orient import build_affine_from_orient_info, reversed_pose_correction, get_origin from .pvobj import PvDatasetDir, PvDatasetZip from .utils import * @@ -13,6 +11,13 @@ import re import warnings np.set_printoptions(formatter={'float_kind':'{:f}'.format}) +import enum + + +@enum.unique +class DataType(enum.Enum): + PVDATASET = 1 + NIFTI1 = 2 def load(path): diff --git a/brkraw/lib/utils.py b/brkraw/lib/utils.py index a75d5f2..048bedc 100644 --- a/brkraw/lib/utils.py +++ b/brkraw/lib/utils.py @@ -1,5 +1,4 @@ -from shleeh.errors import UnexpectedError - +from .errors import UnexpectedError from .reference import * import re import os @@ -7,6 +6,20 @@ from collections import OrderedDict from functools import partial, reduce from copy import copy as cp +import time + + +class TimeCounter: + _start = None + + def __init__(self): + self.reset() + + def reset(self): + self._start = time.time() + + def time(self): + return time.time() - self._start def load_param(stringlist): diff --git a/brkraw/scripts/brkraw.py b/brkraw/scripts/brkraw.py index 2dbc4f9..b49e6c7 100644 --- a/brkraw/scripts/brkraw.py +++ b/brkraw/scripts/brkraw.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- from operator import index -from shleeh import * -from shleeh.errors import * - +from ..lib.errors import * from .. import BrukerLoader, __version__ from ..lib.utils import set_rescale, save_meta_files, mkdir import argparse diff --git a/setup.py b/setup.py index 4e83879..2494c6e 100644 --- a/setup.py +++ b/setup.py @@ -25,8 +25,7 @@ url=__url__, license='GNLv3', packages=find_packages(), - install_requires=['shleeh>=0.1.0', - 'nibabel>=3.0.2', + install_requires=['nibabel>=3.0.2', 'numpy>=1.18.0', 'pandas>=1.0.0', 'pillow>=7.1.1',