Пример #1
0
def new_file_detected(full_path):
    try:
        # Watchman sends the full path to the file. Split it so Shaoqing's code
        # continues to work. TODO: refactor this juggling with dirs and paths.
        pathDir, fileName = os.path.split(full_path)
        pathDir = os.path.join(pathDir, '')  # trailing slash

        src = os.path.join(pathDir, fileName)
        fileDirName, fileExtension = os.path.splitext(src)
        fileExtension = fileExtension.lower()

        usr = get_usr_by_folder(pathDir)

        if usr == 0:
            data_move(src, os.path.join(
                pd['storage_base_path'], pd['rejected_file']))
            logger.error('[x] User-folder does not exist')
            raise Exception('Failed to be authorized!')
        else:
            logger.info('[x] start importing: %r', src)
            logger.info('By User: %r', usr.username)

        if fileExtension == ".filepart":
            fileName = fileName.replace(".filepart", "")
            src = pathDir + fileName
            fileDirName, fileExtension = os.path.splitext(src)
        if fileExtension == ".csv":
            new_fileName = make_file_name_unique(fileName)
            os.rename(pathDir + fileName, pathDir + new_fileName)
            fileName = new_fileName
            src = pathDir + new_fileName
            import_csv(src, usr.id)
        elif fileExtension in [".png", ".jpg", ".jpeg", ".tif", ".tiff"]:
            dst = os.path.join(pd['storage_base_path'], pd['image'])
            import_file(pathDir, fileName, dst, usr.id)
        elif fileExtension in [".avi", ".wmv"]:
            dst = os.path.join(pd['storage_base_path'], pd['video'])
            import_file(pathDir, fileName, dst, usr.id)
        elif fileExtension == ".pdf":
            dst = os.path.join(pd['storage_base_path'], pd['file'])
            import_file(pathDir, fileName, dst, usr.id)
        elif fileExtension == ".geotiff":
            dst = os.path.join(pd['storage_base_path'], pd['geotiff'])
            import_geotiff(pathDir, fileName, dst, usr.id)
        elif fileExtension == ".xml":
            new_fileName = make_file_name_unique(fileName)
            os.rename(pathDir + fileName, pathDir + new_fileName)
            src = pathDir + new_fileName
            fileName = new_fileName
            import_pi_xml(src, usr.id)
        else:
            file_ignored(src, fileExtension)
    except Exception, e:
        logger.error("Unable to process new file %s", src, exc_info=True)
        x = pd['storage_base_path'] + pd['rejected_file']
        y = fileName
        new_file_detected.apply_async((x, y), queue='ddsc.failures')
        raise e
Пример #2
0
def new_socket_detected(pathDir, fileName):
    try:
        src = os.path.join(pathDir, fileName)
        str_path = pd['storage_base_path'] + pd['rejected_file']
        usr = get_usr_by_ip(fileName)

        if usr is False:
            data_move(src, str_path)
            raise Exception("[x] %r _FAILED to be authorized" % src)

        logger.info('[x] start importing: %r', src)
        logger.info('By User: %r', usr.username)
        import_csv(src, usr.id)
    except Exception, e:
        logger.error("Unable to process socket data %s", src, exc_info=True)
        new_socket_detected.apply_async((str_path, fileName),
                queue='ddsc.failures')
        raise e