# -*- coding: iso-8859-1 -*- ## ## Copyright (C) 2008 michael michael[at]vierpi(dot)de ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published ## by the Free Software Foundation; version 2 only. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## # http://www.vierpi.de/JbroutRawWorkflow.html from __main__ import JPlugin from tools import PhotoCmd import os class Plugin(JPlugin): """Plugin to open bibble with the selected pictures.""" __author__ = "michael" __version__ = "1.0" workqueuedir = os.path.expanduser('~/.bibble/work') rawdir = '/proj/media/raw' jbroutdir = '/proj/media/jbrout' bibblebatchdir = '/tmp/bibblebatch' trashdirname = 'trash' bibble = 'bibblepro' def menuEntries(self, l): icons={} icons["openinbibble"] = '/usr/lib/bibblelabs/bibblepro/webhelp/bibble_pro_b.png' icons["synctoraw"] = '/usr/share/icons/gnome/24x24/actions/reload.png' icons["deletetrash"] = '/usr/share/icons/gnome/24x24/status/trashcan_full.png' for i in icons: if not os.path.exists(icons[i]): icons[i] = None return [ (500, _("Open in Bibble"), True, self.openinbibble, icons["openinbibble"]), #(501, _("Reset Bibble Workqueue"), True, self.resetworkqueue, None), #(502, _("Add to Bibble Workqueue"), True, self.addtoworkqueue, None) (503, _("Sync to Raw"), False, self.synctorawFromMenu, icons["synctoraw"]), (504, _("Delete Trash"), False, self.deletetrashFromMenu, icons["deletetrash"]), ] def albumEntries(self,n): return [ (80, _("Sync to Raw"), False, self.synctorawFromAlbum), (81, _("Delete Trash"), False, self.deletetrashFromAlbum), ] def _getrawdir(self, jpgfolder): return jpgfolder.replace(self.jbroutdir, self.rawdir, 1) def _getrawfiles(self, jpgfile): rawdir = self._getrawdir(os.path.dirname(jpgfile)) rawfiles=[] file = os.path.splitext(os.path.basename(jpgfile))[0] for ext in ('.cr2', '.cr2.bib', '.jpg', '.jpg.bib', '.avi', '.mpg'): rawfile = os.path.join(rawdir, file + ext) if os.path.exists(rawfile): rawfiles.append(rawfile) return(rawfiles) def deletemovies(self, folder): movfiles = [os.path.join(folder, mf) for mf in os.listdir(folder) if os.path.splitext(mf)[1] in ('.avi', '.mpg')] for mf in movfiles: if not os.path.exists(os.path.splitext(mf)[0] + '.jpg'): os.remove(mf) def synctoraw(self, folderlist): for fl in folderlist: self.deletemovies(fl) rawdir = self._getrawdir(fl) rawfiles = [os.path.join(rawdir, rf) for rf in os.listdir(rawdir) if rf != self.trashdirname] jpgfiles = [os.path.join(fl, jf) for jf in os.listdir(fl) if os.path.splitext(jf)[1] == '.jpg'] for jf in jpgfiles: for rf in self._getrawfiles(jf): rawfiles.remove(rf) for rf in rawfiles: self.movetotrash(rf) def synctorawFromAlbum(self, node): self.synctoraw((node.file,)) return False def synctorawFromMenu(self, l): folders = [] for f in l: folder = os.path.dirname(f.file) if not folder in folders: folders.append(folder) self.synctoraw(folders) return False def movetotrash(self, file): filedir = os.path.dirname(file) filename = os.path.basename(file) trash = os.path.join(filedir, self.trashdirname) if not os.path.exists(trash): os.mkdir(trash, 0700) os.rename(file, os.path.join(trash, filename)) def deletetrash(self, folderlist): for f in folderlist: rawdir = self._getrawdir(f) trash = os.path.join(rawdir, self.trashdirname) if os.path.exists(trash): for f in os.listdir(trash): os.remove(os.path.join(trash, f)) def deletetrashFromAlbum(self, node): self.deletetrash((node.file,)) return False def deletetrashFromMenu(self, l): folders = [] for f in l: folder = os.path.dirname(f.file) if not folder in folders: folders.append(folder) self.deletetrash(folders) return False def resetworkqueue(self): wf = open(os.path.join(self.workqueuedir, 'jbrout.work'), 'w') print >>wf, 'jbrout' print >>wf def addtoworkqueue(self, l): if not os.path.exists(os.path.join(self.workqueuedir, 'jbrout.work')): wf = open(os.path.join(self.workqueuedir, 'jbrout.work'), 'w') print >>wf, 'jbrout' print >>wf else: wf = open(os.path.join(self.workqueuedir, 'jbrout.work'), 'a') for f in l: filename = os.path.splitext(os.path.basename(f.file))[0] jpgdir = os.path.dirname(f.file) rawfile = os.path.join(self._getrawdir(jpgdir), filename + '.cr2') jpgfile = os.path.join(self._getrawdir(jpgdir), filename + '.jpg') if os.path.exists(rawfile): print >>wf, rawfile else: if os.path.exists(jpgfile): print >>wf, jpgfile def createbibblebatchfolder(self): if not os.path.exists(self.bibblebatchdir): os.mkdir(self.bibblebatchdir, 0700) else: for f in os.listdir(self.bibblebatchdir): os.remove(os.path.join(self.bibblebatchdir, f)) def movebibblebatchfiles(self, l): jpgdict = {} for f in l: jpgdict[os.path.basename(f.file)] = f.file for f in os.listdir(self.bibblebatchdir): if f in jpgdict: pc = PhotoCmd(jpgdict[f]) pc.copyInfoTo(unicode(os.path.join(self.bibblebatchdir, f))) os.rename(os.path.join(self.bibblebatchdir, f), jpgdict[f]) def openinbibble(self, l): self.resetworkqueue() self.addtoworkqueue(l) self.createbibblebatchfolder() os.system(self.bibble) self.movebibblebatchfiles(l) return True