예제 #1
0
def delete_rows_from_table(table, row_ids):
    if row_ids and isinstance(row_ids, str):
        row_ids = list(map(helpers.cast_to_int, row_ids.split(',')))

    if row_ids:
        logger.info(
            "Tautulli Database :: Deleting row ids %s from %s database table",
            row_ids, table)

        # SQlite versions prior to 3.32.0 (2020-05-22) have maximum variable limit of 999
        # https://sqlite.org/limits.html
        sqlite_max_variable_number = 999

        monitor_db = MonitorDatabase()
        try:
            for row_ids_group in helpers.chunk(row_ids,
                                               sqlite_max_variable_number):
                query = "DELETE FROM " + table + " WHERE id IN (%s) " % ','.join(
                    ['?'] * len(row_ids_group))
                monitor_db.action(query, row_ids_group)
            vacuum()
        except Exception as e:
            logger.error(
                "Tautulli Database :: Failed to delete rows from %s database table: %s"
                % (table, e))
            return False

    return True
    formats = ('.JPG', '.jpg', '.PNG', '.png', '.bmp', '.BMP', '.TIFF',
               '.tiff', '.TIF', '.tif')

    try:

        files = [
            file for file in os.listdir(input_path) if file.endswith(formats)
        ]

        procs = cpu_count()
        procIDs = list(range(0, procs))

        numImagesPerProc = len(files) / float(procs)
        numImagesPerProc = int(np.ceil(numImagesPerProc))

        chunkedPaths = list(hs.chunk(files, numImagesPerProc))

        # initialize the list of payloads
        imageLoads = []

        # loop over the set chunked image paths
        for (i, fileNames) in enumerate(chunkedPaths):

            # construct a dictionary of data for the payload, then add it
            # to the payloads list
            data = {
                "id": i,
                "files_names": fileNames,
                "input_path": input_path,
                "output_path": output_path,
                "temp_path": temp_path