def watchDirectories(): """Start watching the watched directories defined in the WatchedDirectories table in the database.""" watched_dir_path = config.get('MCPServer', "watchDirectoryPath") interval = config.getint('MCPServer', "watchDirectoriesPollInterval") watched_directories = WatchedDirectory.objects.all() for watched_directory in watched_directories: directory = watched_directory.watched_directory_path.replace("%watchDirectoryPath%", watched_dir_path, 1) # Tuple of variables that may be used by a callback row = (watched_directory.watched_directory_path, watched_directory.chain_id, watched_directory.only_act_on_directories, watched_directory.expected_type.description) if not os.path.isdir(directory): os.makedirs(directory) for item in os.listdir(directory): if item == ".gitignore": continue item = item.decode("utf-8") path = os.path.join(unicode(directory), item) while(limitTaskThreads <= threading.activeCount() + reservedAsTaskProcessingThreads ): time.sleep(1) createUnitAndJobChainThreaded(path, row, terminate=False) actOnFiles=True if watched_directory.only_act_on_directories: actOnFiles=False watchDirectory.archivematicaWatchDirectory( directory, variablesAdded=row, callBackFunctionAdded=createUnitAndJobChainThreaded, alertOnFiles=actOnFiles, interval=interval, )
def watchDirectories(): """Start watching the watched directories defined in the WatchedDirectories table in the database.""" rows = [] sql = """SELECT watchedDirectoryPath, chain, onlyActOnDirectories, description FROM WatchedDirectories LEFT OUTER JOIN WatchedDirectoriesExpectedTypes ON WatchedDirectories.expectedType = WatchedDirectoriesExpectedTypes.pk""" c, sqlLock = databaseInterface.querySQL(sql) row = c.fetchone() while row != None: rows.append(row) row = c.fetchone() sqlLock.release() for row in rows: directory = row[0].replace("%watchDirectoryPath%", config.get('MCPServer', "watchDirectoryPath"), 1) if not os.path.isdir(directory): os.makedirs(directory) for item in os.listdir(directory): if item == ".gitignore": continue item = item.decode("utf-8") path = os.path.join(unicode(directory), item) #createUnitAndJobChain(path, row) while(limitTaskThreads <= threading.activeCount() + reservedAsTaskProcessingThreads ): time.sleep(1) createUnitAndJobChainThreaded(path, row, terminate=False) actOnFiles=True if row[2]: #onlyActOnDirectories actOnFiles=False watchDirectory.archivematicaWatchDirectory(directory,variablesAdded=row, callBackFunctionAdded=createUnitAndJobChainThreaded, alertOnFiles=actOnFiles, interval=config.getint('MCPServer', "watchDirectoriesPollInterval"))
def watchDirectories(): """Start watching the watched directories defined in the WatchedDirectories table in the database.""" watched_dir_path = django_settings.WATCH_DIRECTORY interval = django_settings.WATCH_DIRECTORY_INTERVAL watched_directories = WatchedDirectory.objects.all() for watched_directory in watched_directories: directory = watched_directory.watched_directory_path.replace("%watchDirectoryPath%", watched_dir_path, 1) # Tuple of variables that may be used by a callback row = (watched_directory.watched_directory_path, watched_directory.chain_id, watched_directory.only_act_on_directories, watched_directory.expected_type.description) if not os.path.isdir(directory): os.makedirs(directory) for item in os.listdir(directory): if item == ".gitignore": continue # We should expect both bytes and unicode. See #932. if isinstance(item, six.binary_type): item = item.decode("utf-8") path = os.path.join(unicode(directory), item) while(django_settings.LIMIT_TASK_THREADS <= threading.activeCount() + django_settings.RESERVED_AS_TASK_PROCESSING_THREADS): time.sleep(1) createUnitAndJobChainThreaded(path, row, terminate=False) actOnFiles = True if watched_directory.only_act_on_directories: actOnFiles = False watchDirectory.archivematicaWatchDirectory( directory, variablesAdded=row, callBackFunctionAdded=createUnitAndJobChainThreaded, alertOnFiles=actOnFiles, interval=interval, )
def watchDirectories(workflow): """Start watching the watched directories defined in the workflow.""" for watched_dir in workflow.get_wdirs(): directory = os.path.join(django_settings.WATCH_DIRECTORY, watched_dir.path.lstrip(os.path.sep)) if not os.path.isdir(directory): os.makedirs(directory) for item in os.listdir(directory): if item == ".gitignore": continue # We should expect both bytes and unicode. See #932. if isinstance(item, six.binary_type): item = item.decode("utf-8") path = os.path.join(six.text_type(directory), item) createUnitAndJobChainThreaded(path, watched_dir, workflow) watchDirectory.archivematicaWatchDirectory( directory, variablesAdded=(watched_dir, workflow), callBackFunctionAdded=createUnitAndJobChainThreaded, alertOnFiles=not watched_dir["only_dirs"], interval=django_settings.WATCH_DIRECTORY_INTERVAL)
def watchDirectories(): """Start watching the watched directories defined in the WatchedDirectories table in the database.""" rows = [] sql = """SELECT watchedDirectoryPath, chain, onlyActOnDirectories, description FROM WatchedDirectories LEFT OUTER JOIN WatchedDirectoriesExpectedTypes ON WatchedDirectories.expectedType = WatchedDirectoriesExpectedTypes.pk""" c, sqlLock = databaseInterface.querySQL(sql) row = c.fetchone() while row != None: rows.append(row) row = c.fetchone() sqlLock.release() for row in rows: directory = row[0].replace( "%watchDirectoryPath%", config.get('MCPServer', "watchDirectoryPath"), 1) if not os.path.isdir(directory): os.makedirs(directory) for item in os.listdir(directory): if item == ".gitignore": continue item = item.decode("utf-8") path = os.path.join(unicode(directory), item) #createUnitAndJobChain(path, row) while (limitTaskThreads <= threading.activeCount() + reservedAsTaskProcessingThreads): time.sleep(1) createUnitAndJobChainThreaded(path, row, terminate=False) actOnFiles = True if row[2]: #onlyActOnDirectories actOnFiles = False watchDirectory.archivematicaWatchDirectory( directory, variablesAdded=row, callBackFunctionAdded=createUnitAndJobChainThreaded, alertOnFiles=actOnFiles, interval=config.getint('MCPServer', "watchDirectoriesPollInterval"))