From b7f8d1fe8a682b5351391de55e108f821a138971 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 11 Jul 2007 12:08:00 +0000 Subject: [PATCH] bootstrap --- oxdbarchive/cron.py | 10 ++++++++++ oxdbarchive/model.py | 32 ++++++++++++++++++++++++-------- oxdbarchive/oxdb_import.py | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/oxdbarchive/cron.py b/oxdbarchive/cron.py index 8a450e9..5d4ffdf 100644 --- a/oxdbarchive/cron.py +++ b/oxdbarchive/cron.py @@ -11,3 +11,13 @@ def findeNew(): def extractNew(): for f in ArchiveFile.select(ArchiveFile.q.extracted == False): f.extractAll() + + +#possible fuctions: +''' +def extractSubtitles(): + #look for rar / sub or vob / sub subtitles and extract them with + #tools/subtitles.py path_to_file + #import srt after + +''' \ No newline at end of file diff --git a/oxdbarchive/model.py b/oxdbarchive/model.py index 2b2235c..87f289f 100644 --- a/oxdbarchive/model.py +++ b/oxdbarchive/model.py @@ -142,6 +142,7 @@ class Archive(SQLObject): return dict(result="file removed") return dict(result="not in archive") + #FIXME this fails for old frontends because it notifies the frontend def importFrontend(self): if self.baseUrlFrontend: dto = socket.getdefaulttimeout() @@ -152,13 +153,22 @@ class Archive(SQLObject): socket.setdefaulttimeout(dto) for f in files: meta = files[f] - meta['path'] = f - meta = oxdb_import.oxdb_file_metadata(meta) - meta['video'] = '' - meta['audio'] = '' - meta['length'] = 0 - meta['bpp'] = 0 - print self.addFile(meta), f + fname = join(self.basePath, f) + if exists(fname): + stats = oxdb_import.oxdb_file_stats(fname) + meta['date'] = stats['date'] + meta['path'] = f + meta['video'] = '' + meta['audio'] = '' + meta['length'] = 0 + meta['bpp'] = 0 + for key in ('bpp', 'size', 'length', 'date'): + meta[key] = int(float(meta[key])) + meta['date'] = datetime.fromtimestamp(meta['date']) + print self.addFile(meta), f + else: + print "remove", f + self.removeFile({'md5sum':meta['md5sum']}) def importFiles(self): stats = {'skipped': 0, 'added': 0, 'remove':0} @@ -189,7 +199,13 @@ class Archive(SQLObject): stats['remove'] += 1 print stats return stats - + + ''' + notify frontend about each file we have. + ''' + def bootstrapFrontend(self): + for f in self.files: + self.notifyFrontend('add', f.md5sum) class ArchiveFile(SQLObject): ''' diff --git a/oxdbarchive/oxdb_import.py b/oxdbarchive/oxdb_import.py index 1bbedae..539b7ab 100644 --- a/oxdbarchive/oxdb_import.py +++ b/oxdbarchive/oxdb_import.py @@ -41,7 +41,7 @@ class OXDb: def oxdb_md5sum(fname): '''Returns an md5 hash for file''' - msum = None + md5sum = None if os.path.exists(fname): f = file(fname, 'rb') m = md5.new()