Esempio n. 1
0
    def __init__(self, **kwargs):
        def imageFileName_process(str_imageFile):
            b_OK = False
            l_indexAndFile = str_imageFile.split(':')
            if len(l_indexAndFile) == 1:
                b_OK = True
                self.str_outputImageFile = l_indexAndFile[0]
            if len(l_indexAndFile) == 2:
                b_OK = True
                self.str_outputImageFile = l_indexAndFile[1]
                self.str_imageIndex = l_indexAndFile[0]
            if not b_OK:
                self.dp.qprint("Invalid image specifier.", comms='error')
                error.fatal(self, 'imageFileSpecFail')
            if len(self.str_outputImageFile):
                self.b_convertToImg = True

        def tagList_process(str_tagList):
            self.str_tagList = str_tagList
            if len(self.str_tagList):
                self.b_tagList = True
                self.l_tag = self.str_tagList.split(',')

        def tagFile_process(str_tagFile):
            self.str_tagFile = str_tagFile
            if len(self.str_tagFile):
                self.b_tagFile = True
                with open(self.str_tagFile) as f:
                    self.l_tag = [x.strip('\n') for x in f.readlines()]

        def outputFile_process(str_outputFile):
            self.str_outputFileType = str_outputFile
            self.l_outputFileType = self.str_outputFileType.split(',')

        # pudb.set_trace()
        self.declare_selfvars()

        for key, value in kwargs.items():
            if key == "inputDir": self.str_inputDir = value
            if key == "inputFile": self.str_inputFile = value
            if key == "extension": self.str_extension = value
            if key == "outputDir": self.str_outputDir = value
            if key == "outputFileStem": self.str_outputFileStem = value
            if key == "outputFileType": outputFile_process(value)
            if key == 'printToScreen': self.b_printToScreen = value
            if key == 'imageFile': imageFileName_process(value)
            if key == 'tagFile': tagFile_process(value)
            if key == 'tagList': tagList_process(value)
            if key == 'verbosity': self.verbosityLevel = int(value)

        # Set logging
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               level=0,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)

        if not len(self.str_inputDir): self.str_inputDir = '.'
Esempio n. 2
0
    def __init__(self, **kwargs):
        """
        A "base" class for all pfdicom objects. This class is typically never 
        called/used directly; derived classes are used to provide actual end
        functionality.

        This class really only reads in a DICOM file, and populates some
        internal convenience member variables.

        Furthermore, this class does not have a concept nor concern about 
        "output" relations.
        """
        def outputDir_process(str_outputDir):
            if str_outputDir == '%inputDir':
                self.str_outputDir = self.str_inputDir
            else:
                self.str_outputDir = str_outputDir

        # pudb.set_trace()
        pfdicom.declare_selfvars(self)

        for key, value in kwargs.items():
            if key == 'inputDir': self.str_inputDir = value
            if key == 'maxDepth': self.maxDepth = int(value)
            if key == 'inputFile': self.str_inputFile = value
            if key == "outputDir": outputDir_process(value)
            if key == 'outputFileStem': self.str_outputFileStem = value
            if key == 'outputLeafDir': self.str_outputLeafDir = value
            if key == 'extension': self.str_extension = value
            if key == 'threads': self.numThreads = int(value)
            if key == 'extension': self.str_extension = value
            if key == 'verbosity': self.verbosityLevel = int(value)
            if key == 'json': self.b_json = bool(value)
            if key == 'followLinks': self.b_followLinks = bool(value)

        # Declare pf_tree
        self.pf_tree = pftree.pftree(inputDir=self.str_inputDir,
                                     maxDepth=self.maxDepth,
                                     inputFile=self.str_inputFile,
                                     outputDir=self.str_outputDir,
                                     outputLeafDir=self.str_outputLeafDir,
                                     threads=self.numThreads,
                                     verbosity=self.verbosityLevel,
                                     followLinks=self.b_followLinks,
                                     relativeDir=True)

        # Set logging
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)
Esempio n. 3
0
    def __init__(self, **kwargs):

        # pudb.set_trace()
        self.declare_selfvars()

        for key, value in kwargs.items():
            if key == 'inputDir': self.str_inputDir = value
            if key == 'maxDepth': self.maxdepth = int(value)
            if key == 'inputFile': self.str_inputFile = value
            if key == 'outputDir': self.str_outputDir = value
            if key == 'verbosity': self.verbosityLevel = int(value)
            if key == 'threads': self.numThreads = int(value)
            if key == 'relativeDir': self.b_relativeDir = bool(value)
            if key == 'stats': self.b_stats = bool(value)
            if key == 'statsReverse': self.b_statsReverse = bool(value)
            if key == 'jsonStats': self.b_jsonStats = bool(value)
            if key == 'json': self.b_json = bool(value)
            if key == 'followLinks': self.b_followLinks = bool(value)
            if key == 'test': self.str_sleepLength = value
            if key == 'outputLeafDir': self.str_outputLeafDir = value

        if len(self.str_sleepLength):
            l_test = self.str_sleepLength.split(':')
            self.str_sleepLength = l_test[0]
            if len(l_test) == 2:
                self.testType = int(l_test[1])
            try:
                self.f_sleepLength = float(self.str_sleepLength)
                self.b_test = True
            except:
                self.b_test = False

        # Set logging
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)

        if not len(self.str_inputDir): self.str_inputDir = '.'
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        """
        The constructor for the tagExtractor, with specializations over the
        base pfdicom class.
        """
        def imageFileName_process(str_imageFile):
            b_OK = False
            l_indexAndFile = str_imageFile.split(':')
            if len(l_indexAndFile) == 1:
                b_OK = True
                self.str_outputImageFile = l_indexAndFile[0]
            if len(l_indexAndFile) == 2:
                b_OK = True
                self.str_outputImageFile = l_indexAndFile[1]
                self.str_imageIndex = l_indexAndFile[0]
            if not b_OK:
                self.dp.qprint("Invalid image specifier.", comms='error')
                error.fatal(self, 'imageFileSpecFail', drawBox=True)
            if len(self.str_outputImageFile):
                self.b_convertToImg = True

        def imageScale_process(str_imageScale):
            if len(str_imageScale):
                try:
                    str_scale, str_interpolation = str_imageScale.split(':')
                    self.str_interpolation = str_interpolation
                except:
                    str_scale = str_imageScale
                self.f_imageScale = float(str_scale)

        def tagList_process(str_tagList):
            self.str_tagList = str_tagList
            if len(self.str_tagList):
                self.b_tagList = True
                self.l_tag = self.str_tagList.split(',')

        def tagFile_process(str_tagFile):
            self.str_tagFile = str_tagFile
            if len(self.str_tagFile):
                self.b_tagFile = True
                with open(self.str_tagFile) as f:
                    self.l_tag = [x.strip('\n') for x in f.readlines()]

        def outputFile_process(str_outputFile):
            self.str_outputFileType = str_outputFile
            self.l_outputFileType = self.str_outputFileType.split(',')

        pfdicom_tagExtract.declare_selfvars(self)

        # Process some of the kwargs by the base class
        super().__init__(*args, **kwargs)

        for key, value in kwargs.items():
            if key == "outputFileType": outputFile_process(value)
            if key == 'printToScreen': self.b_printToScreen = bool(value)
            if key == 'useIndexhtml': self.b_useIndexhtml = bool(value)
            if key == 'imageFile': imageFileName_process(value)
            if key == 'imageScale': imageScale_process(value)
            if key == 'tagFile': tagFile_process(value)
            if key == 'tagList': tagList_process(value)
            if key == 'verbosity': self.verbosityLevel = int(value)

        # Set logging
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        """
        Constructor for pfdicom_tagSub.

        Basically sets some derived class specific member variables (with
        explicit call to *this* class) and then calls super class
        constructor.
        """
        def tagStruct_process(str_tagStruct):
            self.str_tagStruct = str_tagStruct
            if len(self.str_tagStruct):
                self.d_tagStruct = json.loads(str_tagStruct)

        def set_splitToken(str_splitToken):
            self.str_splitToken = str_splitToken

        def tagInfo_to_tagStruct(str_tagInfo):
            self.str_tagInfo = str_tagInfo

            lstrip = lambda l: [x.strip() for x in l]

            if self.str_tagInfo and self.str_tagStruct:
                raise ValueError(
                    "You must specify either tagStruct or tagInfo, not both")

            # Split the string into key/value components
            l_sdirty: list = self.str_tagInfo.split(self.str_splitToken)

            # Now, strip any leading and trailing spaces from list elements
            l_s: list = lstrip(l_sdirty)
            d: dict = {}

            l_kvdirty: list = []
            l_kv: list = []
            try:
                for f in l_s:
                    l_kvdirty = f.split(self.str_splitKeyValue)
                    l_kv = lstrip(l_kvdirty)
                    d[l_kv[0]] = l_kv[1]
            except:
                print('Incorrect tag info specified')
                return

            # self.d_tagStruct            = json.loads(json.dumps(dict(d)))
            self.d_tagStruct = d.copy()

        def tagFile_process(str_tagFile):
            self.str_tagFile = str_tagFile
            if len(self.str_tagFile):
                self.b_tagFile = True
                with open(self.str_tagFile) as f:
                    self.d_tagStruct = json.load(f)

        def outputFile_process(str_outputFile):
            self.str_outputFileType = str_outputFile

        # pudb.set_trace()
        pfdicom_tagSub.declare_selfvars(self)

        # Process some of the kwargs by the base class
        super().__init__(*args, **kwargs)

        for key, value in kwargs.items():
            if key == "outputFileType": outputFile_process(value)
            if key == 'tagFile': tagFile_process(value)
            if key == 'tagStruct': tagStruct_process(value)
            if key == 'splitToken': set_splitToken(value)
            if key == 'tagInfo': tagInfo_to_tagStruct(value)
            if key == 'splitKeyValue': self.str_splitKeyValue = value
            if key == 'verbosity': self.verbosityLevel = int(value)

        # Set logging
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)
Esempio n. 6
0
    def declare_selfvars(self, *args, **kwargs):
        """
        A block to declare self variables
        """
        def outputDir_process(str_outputDir):
            if str_outputDir == '%inputDir':
                self.str_outputDir = self.str_inputDir
            else:
                self.str_outputDir = str_outputDir

        #
        # Object desc block
        #
        self.args = kwargs
        self.__name__ = "tsmake"

        # Init some vars
        self.b_noLogos = False
        self.str_additionalDirList = ""

        # Parse CLI args
        for key, value in kwargs.items():
            if key == 'inputDir': self.str_inputDir = value
            if key == "outputDir": outputDir_process(value)
            if key == 'verbosity': self.verbosityLevel = int(value)
            if key == 'b_noLogos': self.b_noLogos = bool(value)
            if key == 'fortune': self.fortuneSlides = int(value)
            if key == 'slidePrefixDOMID': self.str_slidePrefixDOMID = value
            if key == 'slideListGlob': self.str_slideListGlob = value
            if key == 'slideTextNumRows': self.textNumRows = int(value)
            if key == 'slidesFile': self.str_slidesFile = value
            if key == 'slidesFileBreak': self.str_slidesFileBreak = value
            if key == 'additionalDirList': self.str_additionalDirList = value

        # Slide lists and dictionaries
        self.lstr_slideFiles = []
        self.ld_slide = []
        self.str_extension = "hjson"

        #----------------- state --------------------
        # There are some implicit assumptions in the
        # underlying pfstate module that need to be
        # addressed in future versions of that module
        self.args['args'] = {}
        self.args['args']['str_configFileLoad'] = ''
        self.args['args']['str_configFileSave'] = ''
        self.args['args']['str_debugToDir'] = '/tmp'
        self.args['args']['verbosity'] = self.args['verbosity']
        self.state = D(**self.args)
        self.data = self.state.T

        # pftree dictionary
        self.pf_tree = None
        self.numThreads = 1

        # Some output handling
        self.str_stdout = ''
        self.str_stderr = ''
        self.exitCode = 0

        # Convenience vars
        self.dp = pfmisc.debug(verbosity=self.verbosityLevel,
                               within=self.__name__)
        self.log = pfmisc.Message()
        self.log.syslog(True)
        self.tic_start = 0.0
        self.pp = pprint.PrettyPrinter(indent=4)