Beispiel #1
0
def test_check_if_exists():
    log = logging.getLogger('test_check_if_exists')
    log.debug('Testing function for checking if a file exists')

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

    assert f.check_if_exists() is True
Beispiel #2
0
        if args.type is not None:
            logger.debug('Type provided using -t, --type option')
            f = File(name=path, type=args.type, md5=md5sum)
        else:
            logger.debug('No file type provided using -t, --type option')
            logger.debug('File type will be deduced using file extension')
            f = File(name=path, settingsf=args.settings, md5=md5sum)
            ftype = f.guess_type()
            f.type = ftype
        files.append(f)
else:
    raise Exception("You need to provide the file/s to be loaded using either "
                    "the -f, -l or --md5_file options")

for f in files:
    if f.check_if_exists() is False:
        print(
            f"There was an error when trying to load: {f.name}. Wrong file path"
        )
        sys.exit(1)
    if str2bool(args.unique) is True:
        # get basename and check if it already exists in DB
        basename = os.path.basename(f.name)
        rf = db.fetch_file(basename=basename)
        assert rf is None, f"A file with the name '{basename}' already exists in the DB. You need to change the name " \
                           f"'{basename}' so it is unique."

    db.load_file(f, dry=str2bool(args.dry))

logger.info('Running completed')