cc-4105: Extended api of SyncDB and improved the launcher script

This commit is contained in:
root 2012-07-20 17:13:00 -04:00 committed by Rudi Grinberg
parent 6a7cb50d67
commit 587292c963
4 changed files with 53 additions and 11 deletions

View file

@ -44,6 +44,11 @@ class IncludeOnly(object):
if ext in self.exts: func(moi, event, *args, **kwargs)
return _wrap
def partition(f, alist):
# TODO : document this function and add doctests
return (filter(f, alist), filter(lambda x: not f(x), alist))
def is_file_supported(path):
# TODO : test and document this function
return extension(path) in supported_extensions

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
from media.monitor.log import Loggable
class SyncDB(Loggable):
@ -15,12 +16,27 @@ class SyncDB(Loggable):
# self.directories is a dictionary where a key is the directory and the
# value is the directory's id in the db
self.directories = dict( (v,k) for k,v in directories.iteritems() )
# Just in case anybody wants to lookup a directory by its id we haev
self.id_lookup = directories
def list_directories(self):
"""
returns a list of all the watched directories in the datatabase.
"""
return self.directories.keys()
def directory_get_files(self, directory):
print("trying to access dir id: %s" % self.directories[directory])
self.apc.list_all_db_files(self.directories[directory])
"""
returns all the files(recursively) in a directory. a directory is an "actual" directory
path instead of it's id.
"""
return [ os.path.normpath(os.path.join(directory,f)) \
for f in self.apc.list_all_db_files(self.directories[directory]) ]
def id_get_files(self, dir_id):
"""
returns all the files given some dir_id. this method is here for "symmetry". it's not actually used anywhere
"""
return self.directory_get_files(self.id_get_files[dir_id])