Example #1
0
 def check(self):
 
     if self.options.info: pass
     elif self.options.fb: pass
     elif self.options.fromDir:
         if not isdir(self.options.fromDir):
             _err_exit('Not a directory: %s' % self.options.fromDir)
     elif not self.options.albumName:
         _err_exit('missing albumName argument')
         
     if not self.options.verbose:
         quiet()
Example #2
0
    def getPhotoFromId(self, pic_id):
        p = self.data['Master Image List'][pic_id]
        photoFileName = p['ImagePath']

	# FIXME: This is a mess:
	# Can we simplify it with dictionnaries and / or regexp ?
        if self.libraryPath:
            try:
                if 'Originals' in photoFileName:
                    index = photoFileName.index('Originals')
                    photoFileName = join(self.libraryPath, photoFileName[index:])
                elif 'Modified' in photoFileName:
                    index = photoFileName.index('Modified')
                    photoFileName = join(self.libraryPath, photoFileName[index:])
                else:
                    # iPhoto 2 (Panther)
		    if 'iPhoto Library' in photoFileName:
			suffix = photoFileName.split('iPhoto Library' + '/')[1]
		    elif 'iPhotoLibrary' in photoFileName:
			suffix = photoFileName.split('iPhotoLibrary' + '/')[1]
                    photoFileName = join(self.libraryPath, suffix)
                    
            except (ValueError):
                # probably panther iPhoto, there is no Original in the filename
                print self.libraryPath
                _err_exit('Internal Error: cannot handle %s' %(photoFileName))

            logger.info(photoFileName)
        else:
            raise AlbumDataError, "Internal error: libraryPath not defined"

        if not p.has_key('DateAsTimerInterval'):
            p['DateAsTimerInterval'] = ''
            
        return Photo(photoFileName,
                     pic_id,
                     p['Caption'],
                     p['Comment'],
                     p['DateAsTimerInterval'])
Example #3
0
    def __init__(self, confDir=None):

        self.ok = False

        try:
            if confDir == None:
                confDir = join(expanduser('~'),'.pytof')
            if not exists(confDir):
                os.makedirs(confDir)
            self.confDir = confDir
        except(os.error):
            _err_exit('Cannot create %s' %(confDir))
            return

        # from now on, it should be safe as we were able to
        # create the main dir
        confFilename = join(self.confDir, 'pytof.ini')

        exist = exists(confFilename)
        if exist:
            size = getsize(confFilename)

        if not exist or size == 0:
            # create it
            logger.info('Create brand new config file')
            # FIXME: this file may contains password, it has to be
            # created in 600 mode (os.chmod ?)
            confFd = open(confFilename, 'w')
            confFd.write(self.template)
            confFd.close()

        self.confFilename = confFilename

        self.pickleFilename = join(self.confDir, 'xmlData.pickle')
        self.exifFilename = join(self.confDir, 'exif.pickle')
        logger.info(self.pickleFilename)
        self.Load()
        self.ok = True
Example #4
0
#!/usr/bin/env python
# env python works on Mac while /usr/bin/python does not ...

from sys import argv, exit

from utils import _err_exit, notYetImplemented
from scene import ArgsOptions

try:
    from OpenGL.GLUT import *
except ImportError:
    _err_exit('ERROR: PyOpenGL not installed properly.')

window_title = 'Python GLUT obj viewer'
window_title = ''


def ogl_motion(x, y):
    manip_mode = {
        GLUT_LEFT_BUTTON: 'rotate',
        GLUT_MIDDLE_BUTTON: 'pan',
        GLUT_RIGHT_BUTTON: 'zoom'
    }
    sdk.pointer_move(manip_mode.get(sdk.button, 'rotate'), sdk.mouse_start[0],
                     sdk.mouse_start[1], x, y)
    sdk.mouse_start = [x, y]

    glutPostRedisplay()  # ask for a refresh


def ogl_mouse(button, button_state, x, y):
Example #5
0
def main(albumName, topDir, xmlData, strip_originals, style, fromDir, progress=None):
    logger.info("strip_originals = %s" % strip_originals)
    if progress == None:
        progress = ProgressMsg(0, sys.stderr)
    data = xmlData
    if fromDir:
        data = AlbumDataFromDir(fromDir)

    leafDirs = ["photos", "preview", "thumbs"]
    dirs = []
    for leafDir in leafDirs:
        Dir = join(topDir, leafDir)
        dirs.append(Dir)
        if not os.path.exists(Dir):
            try:
                os.makedirs(Dir)
            except (os.error):
                _err_exit("Cannot create %s" % (Dir))

    # Create magic file
    fo = open(join(topDir, ".magic"), "w")
    fo.close()

    logger.info(topDir)

    # photo per page
    thumbs = []
    logger.info("Writing pictures\n")

    photos = data.getPicturesIdFromAlbumName(albumName)
    progress.target = len(photos)
    for i in xrange(len(photos)):

        pic_id = photos[i]
        logger.debug("processing photo %s" % pic_id)

        photo = data.getPhotoFromId(pic_id)
        prev = data.getPhotoFromId(photos[i - 1])
        try:
            next = data.getPhotoFromId(photos[i + 1])
        except (IndexError):
            # ok I know it's crappy programming :)
            next = data.getPhotoFromId(photos[0])

        if not strip_originals:
            photo.saveCopy(dirs[0])
        photo.makePreview(dirs[1], 640)
        photo.makeThumbnail(dirs[2])

        # FIXME: makePhotoPage return photoPageName which shoule be
        # modified to HTML/123.html. We would only have to create
        # a dir HTML, change the links in the index to HTML/123.html
        # and create the per page file in HTML/123.html
        makePhotoPage(photo, topDir, prev, next, strip_originals, albumName, style)
        thumbs.append(Thumb(photo.id + ".html", "/".join(["thumbs", "th_" + photo.id + photo.getFileType()])))
        progress.Increment()

    # gallery index
    dico = {}
    dico["title"] = albumName
    dico["thumbs"] = thumbs

    pt = pytofTemplate()
    pt.write("index", dico, join(topDir, "index") + ".html", style)

    # main index (list of all galleries)
    dico = {}
    dico["title"] = albumName
    dicoThumbs = []
    mainDir = join(topDir, os.pardir)
    logger.debug("main dir: %s" % mainDir)
    for album in os.listdir(mainDir):
        if not isdir(join(mainDir, album)):
            continue
        if not exists(join(mainDir, album, ".magic")):
            continue

        logger.debug("Found gallery %s" % album)
        thLink = "/".join([album, "index.html"])
        thDir = join(mainDir, album, "thumbs")

        thumbs = os.listdir(thDir)
        # glob like command to remove .DS_STORE files
        thumbs = [t for t in thumbs if t.startswith("th_")]
        if len(thumbs) > 0:
            thImage = "/".join([album, "thumbs", thumbs[0]])
            dicoThumbs.append(Thumb(thLink, thImage, album))

    dico["gallery_thumb"] = dicoThumbs
    pt.write("main", dico, join(mainDir, "index") + ".html", style)
Example #6
0
#!/usr/bin/env python
# env python works on Mac while /usr/bin/python does not ...

from sys import argv, exit

from utils import _err_exit, notYetImplemented
from scene import ArgsOptions

try:
    from OpenGL.GLUT import *
except ImportError:
    _err_exit('ERROR: PyOpenGL not installed properly.')

window_title = 'Python GLUT obj viewer'
window_title = ''

def ogl_motion(x, y):
    manip_mode = {
            GLUT_LEFT_BUTTON: 'rotate',
            GLUT_MIDDLE_BUTTON: 'pan',
            GLUT_RIGHT_BUTTON: 'zoom'
            }
    sdk.pointer_move(manip_mode.get(sdk.button, 'rotate'), 
            sdk.mouse_start[0], sdk.mouse_start[1], x, y)
    sdk.mouse_start = [x, y]

    glutPostRedisplay() # ask for a refresh

def ogl_mouse(button, button_state, x, y):
    sdk.button = button
    sdk.motion = button_state
Example #7
0
    def main(self):
        # init the config file
        conf = configHandler()
        if not conf.ok:
            _err_exit('Problem with the config file')

        libraryPath, xmlFileName, outputDir = \
                     conf.getValuesAndUpdateFromUser(self.libraryPath,
                                                     self.xmlFileName,
                                                     self.outputDir)

        ##
        # get iPhoto datas or flat dir pictures list
        if self.fb:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            self.albumName = 'My Facebook pictures'
            self.fromDir = '/tmp/fb_files'

            facebook_download(self.fromDir, self.fb_uid)
            # sys.exit(0)

        elif not self.fromDir:
            try:
                adp = AlbumDataParser(libraryPath, xmlFileName)
                xmlData = adp.maybeLoadFromXML(conf)
            except(AlbumDataParserError):
                _err_exit("Problem parsing AlbumData.xml")
        else:
            logger.info('generate gallery from photos in %s dir' % self.fromDir)
            xmlData = None
            # FIXME: this '/' may not be portable ...
            self.albumName = basename(rstrip(self.fromDir, '/'))
            logger.info('albumName is %s' % self.albumName)

	# FIXME: remove the output dir if a problem occur
        up = 'pytof'
        topDir = join(self.outputDir, up, self.albumName)
        try:
            if not exists(topDir):
                os.makedirs(topDir)
        except (os.error):
            _err_exit('Cannot create %s' %(topDir))

        echo('output dir is %s' % (topDir))

        try:
            if self.info:
                for a in xmlData.getAlbumList():
                    try: 
                        print a.encode('utf8')
                    except UnicodeDecodeError:
                        print a
            else:
                if self.fs:
                    makefs.main(self.albumName, topDir, xmlData)
                else:
                    makepage.main(self.albumName, topDir, xmlData,
                                  self.stripOriginals, self.style,
                                  self.fromDir, self.progress)

            archive = None
            if self.Zip or self.tar:
                archive = mkarchive(fn = join(outputDir, up, self.albumName),
                                    prefix = join(outputDir, up),
                                    mainDir = self.albumName,
                                    files = [],
                                    Zip = self.Zip,
                                    tar = self.tar)
                echo('output archive is %s' % (archive))

            if not self.info and not self.fs:
                import webbrowser
                url = 'file:///'
                url += '/'.join(topDir.split(sep)) + '/'
                url += '/'.join(['..', 'index.html'])
                webbrowser.open(url)

            if self.ftp:
                ftpPush(conf, archive, topDir, self.fs)

        except (KeyboardInterrupt):

            if not self.info:
                if not self.fs:
                    # os.remove(makepage.cssfile)
                    # we should remove the css file if there aren't
                    # any other exported albums left... hard to know,
                    # may be stored in the rc file, under the Internal section.
                    # => if that's the only file in the pytof dir we should be good to go.
                    pass

                if exists(topDir):
                    rmtree(topDir)

                _err_exit("\nAborted by user")