Beispiel #1
0
def makePhotoPage(photo, topDir, prev, next, strip_originals, albumName, style):
    """ 
    Create the per photo page, with a next and prev link
    Each link has a thumbnail in scry style mode
    """
    dico = {}
    dico["album_name"] = albumName
    dico["title"] = photo.id + photo.getFileType()
    dico["width"] = str(photo.width)
    dico["height"] = str(photo.height)
    dico["size"] = str(photo.sizeKB)
    dico["exif_infos"] = photo.exif_infos
    dico["preview"] = "/".join(["preview", "pv_" + photo.id + photo.getFileType()])
    dico["preview_filename"] = basename(dico["preview"])
    dico["prev"] = prev.id + ".html"
    dico["prev_thumb"] = "/".join(["thumbs", "th_" + prev.id + prev.getFileType()])
    dico["next"] = next.id + ".html"
    dico["next_thumb"] = "/".join(["thumbs", "th_" + next.id + next.getFileType()])

    original = ("/").join(["photos", photo.id + photo.getFileType()])
    if strip_originals:
        original = ""
    dico["original"] = original

    pt = pytofTemplate()
    pt.write("photo", dico, join(topDir, photo.id) + ".html", style)
Beispiel #2
0
    def __init__(self):

        pt = pytofTemplate()

        # parse args
        parser = OptionParser(usage = "usage: python %prog <options>",
                              version = "%prog " + __version__)

        parser.add_option("-a", "--album", dest="albumName", default='',
                          help="The iPhoto library album to process (it can be a list, comma separated")
        parser.add_option("-i", "--info",
                      action="store_true", dest="info", default=False,
                          help="Print info about the collection [default = %default]")
        parser.add_option("-o", "--output", dest="outputDir", default=expanduser('~'),
                          help="The output directory [%default + pytof/ALBUMNAME]")
        parser.add_option("-f", "--file-system",
                          action="store_true", dest="fs", default=False,
                          help="Extract album photo to OUTPUTDIR and stop")
        parser.add_option("-t", "--tar-archive",
                          action="store_true", dest="tar", default=False,
                          help="Create a tar archive from the exported datas")
        parser.add_option("-z", "--zip-archive",
                          action="store_true", dest="Zip", default=False,
                          help="Create a tar archive from the exported datas")
        parser.add_option("-v", "--verbose",
                          action="store_true", dest="verbose", default=False,
                          help="Report a number of information")
        parser.add_option("-l", "--library", dest="libraryPath", default='',
                          help="The iPhoto library directory path"),
        parser.add_option("-x", "--xml-file", dest="xmlFileName", default='',
                          help="The iPhoto library XML file name")
        parser.add_option("-u", "--ftp-upload",
                          action="store_true", dest="ftp", default=False,
                          help="Upload pytof output to a ftp site")
        parser.add_option("-s", "--strip-originals",
                          action="store_true", dest="stripOriginals", default=False,
                          help="Remove the originals from the generated gallery Gallery will be way smaller")
        parser.add_option("-d", "--from-directory", dest="fromDir", default='',
                          help="The directory path for the gallery. Do not interact with iPhoto")
        parser.add_option("-c", "--gallery-style", dest="style", default='scry',
                          type="choice", choices=pt.styles,
                          help="The style of the HTML gallery.")
        parser.add_option("-p", "--profile", action="store_true", dest="pyprofile",
                          default=False, help="Enable python profile module profiling  [default=%default]")
        parser.add_option("-b", "--fb", action="store_true", dest="fb",
                          default=False, help="Use user Facebook gallery as input")
        parser.add_option("-g", "--fb-uid", dest="fb_uid", default=None,
                          help="The facebook user you want pictures from")

        self.options, args = parser.parse_args()
Beispiel #3
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)