예제 #1
0
def test_guess_type():
    log = logging.getLogger('test_guess_type')
    log.debug('Testing function for guess the type of a file')

    f = File(name=f"{os.getenv('DATADIR')}/test.txt")

    assert f.guess_type() == "TXT"
예제 #2
0
def test_guess_type_default():
    log = logging.getLogger('test_guess_type_default')
    log.debug('Testing function to check when a default '
              'type is assigned when the extension is'
              'not recognised')

    new_fname = f"{os.getenv('DATADIR')}/test.2020.pippo"
    f = File(name=new_fname)

    assert f.guess_type() == "MISC"
예제 #3
0
def test_guess_type1(rand_file):
    log = logging.getLogger('test_guess_type1')
    log.debug('Testing function for guess the type of a complex filename')
    new_fname = f"{os.getenv('DATADIR')}/test_arch.2020.txt"
    # change the basename to something more complex
    os.rename(f"{os.getenv('DATADIR')}/test_arch.txt", new_fname)
    f = File(name=new_fname)

    # delete test type
    os.remove(new_fname)
    assert f.guess_type() == "TXT"
예제 #4
0
    def print_changelog(self, ifile):
        """
        Function that adds an entry to the CHANGELOG report
        file

        Parameters
        ----------
        ifile : str
                path to CHANGELOG file that will be updated.
        
        Returns
        -------
        None
        """
        now_str = self.dtime.strftime('%Y-%m-%d')
        now_str1 = self.dtime.strftime('%Y%m%d')

        lines_to_add = now_str + "\n\n"
        for state, value in self.__dict__.items():
            size = 0
            if type(value) is set:
                size = len(value)
            elif type(value) is dict:
                size = len(value.keys())
            if size == 0: continue
            types = []
            for p in value:
                # create File object to get its type
                fObj = File(name=p)
                types.append(fObj.guess_type())
            # remove duplicates from list
            types = list(set(types))
            types = [s.lower() for s in types]
            # get the changelog_details dir from config
            dirname = CONFIG.get('ctree', 'chlog_details_dir')
            lines_to_add += "Modification to: {0}\n\n".format(",".join(types))
            lines_to_add += "Details can be found in\n" \
                            "{0}/changelog_details_{1}_{2}\n\n".format(dirname,
                                                                       now_str1, state)
        with open(ifile, 'r+') as f:
            content = f.read()
            f.seek(0, 0)
            f.write(lines_to_add.rstrip('\r\n') + '\n\n' + content)
예제 #5
0
# Class to connect with Reseqtrack DB
db = DB(pwd=pwd, dbname=dbname)

# list with paths to be loaded
files = []
if args.file:
    logger.info('File provided using -f, --file option')

    if args.type is not None:
        logger.debug('Type provided using -t, --type option')
        f = File(name=args.file, type=args.type)
    else:
        logger.debug('No file type provided using -t, --type option')
        logger.debug('File type will be guessed from its file extension')
        f = File(name=args.file, settingsf=args.settings)
        ftype = f.guess_type()
        f.type = ftype
    files.append(f)

elif args.list_file:
    logger.info('File with paths provided using -l, --list_file option')

    for path in args.list_file:
        path = path.rstrip("\n")
        cols = re.split(' +', path)
        if len(cols) > 1:
            raise Exception(f"Path provided {path} is not correct. "
                            f"Check format")

        if args.type is not None:
            logger.debug('Type provided using -t, --type option')