示例#1
0
def main():
    parser = get_option_parser()
    (options, args) = parser.parse_args()
    if not options.iphoto:
        parser.error("Need to specify the iPhoto library with the --iphoto "
                     "option.")            
    
    album_xml_file = iphotodata.get_album_xmlfile(
        su.expand_home_folder(options.iphoto))
    data = iphotodata.get_iphoto_data(album_xml_file)
    
    
    if options.pathes_file and options.ids_file:
        f_pathes = codecs.open(options.pathes_file,'w',"utf-16be")
        f_ids = codecs.open(options.ids_file,'w',"utf-16be")
        for image in data.images_by_id.values():
            f_ids.write(image.key)
            f_ids.write("\0")
            f_pathes.write(image.getimagepath())
            f_pathes.write("\0")
    
        f_pathes.close
        f_ids.close     
    
    if options.albums_file:
        f_albums = codecs.open(options.albums_file,'w',"utf-16be")
        events = data._getrolls();
        for event in events:
            f_albums.write("")
            f_albums.write("\0")
            f_albums.write(event.albumid)
            f_albums.write("\0")
            f_albums.write(event.name)
            f_albums.write("\0")
            f_albums.write("")
           # f_albums.write("\0")
            
            for image in event.images:
                f_albums.write(image.key)
                f_albums.write("\0")
            
            f_albums.write("\0")
            f_albums.write("\0")
示例#2
0
    def export_thread(self, mode):
        """Run an export operation in a thread, to not block the UI.

        Args:
            mode - name of operation to run, "library", "dry_run", or "export".
        """
        try:
            # First, load the iPhoto library.
            library_path = su.expand_home_folder(self.iphoto_library.get())
            album_xml_file = None
            try:
                album_xml_file = iphotodata.get_album_xmlfile(library_path)
            except ValueError, e:
                self.thread_queue.put(("done", (False, mode, str(e))))
                return

            album_sql_file = None
            try:
                album_sql_file = iphotodata.get_album_sqlfile(library_path)
            except ValueError, e:
                self.thread_queue.put(("done", (False, mode, str(e))))
                return
示例#3
0
def main():
    """main routine for phoshare."""
    parser = get_option_parser()
    (options, args) = parser.parse_args()
    if len(args) != 0:
        parser.error("Found some unrecognized arguments on the command line.")

    if options.version:
        print '%s %s' % (phoshare.phoshare_version.PHOSHARE_VERSION,
                         phoshare.phoshare_version.PHOSHARE_BUILD)
        return 1

    if options.iptc > 0 and not exiftool.check_exif_tool():
        print >> sys.stderr, (
            "Exiftool is needed for the --itpc or --iptcall" + " options.")
        return 1

    if options.size and options.link:
        parser.error("Cannot use --size and --link together.")

    if not options.iphoto:
        parser.error("Need to specify the iPhoto library with the --iphoto "
                     "option.")

    if options.export or options.picasaweb or options.checkalbumsize:
        if not (options.albums or options.events or options.smarts
                or options.facealbums):
            parser.error("Need to specify at least one event, album, or smart "
                         "album for exporting, using the -e, -a, or -s "
                         "options.")
    else:
        parser.error("No action specified. Use --export to export from your "
                     "iPhoto library.")

    if options.picasaweb:
        if options.picasapassword:
            google_password = options.picasapassword
        else:
            google_password = getpass.getpass('Google password for %s: ' %
                                              options.picasaweb)

    logging_handler = logging.StreamHandler()
    logging_handler.setLevel(
        logging.DEBUG if options.verbose else logging.INFO)
    _logger.addHandler(logging_handler)

    album_xml_file = iphotodata.get_album_xmlfile(
        su.expand_home_folder(options.iphoto))
    data = iphotodata.get_iphoto_data(album_xml_file)
    if data.aperture:
        if options.originals:
            data.load_aperture_originals()
        check_aperture_mode(options, parser)

    options.aperture = data.aperture
    options.foldertemplate = unicode(options.foldertemplate)
    options.nametemplate = unicode(options.nametemplate)
    options.captiontemplate = unicode(options.captiontemplate)

    if options.checkalbumsize:
        data.checkalbumsizes(int(options.checkalbumsize))

    if options.export:
        album = ExportLibrary(su.expand_home_folder(options.export))
        export_iphoto(album, data, options.exclude, options)
    if options.picasaweb:
        albums = picasaweb.PicasaAlbums(options.picasaweb, google_password)
        export_iphoto(albums, data, options.exclude, options)
示例#4
0
    def export_thread(self, mode):
        """Run an export operation in a thread, to not block the UI.

        Args:
            mode - name of operation to run, "library", "dry_run", or "export".
        """
        try:
            # First, load the iPhoto library.
            library_path = su.expand_home_folder(self.iphoto_library.get())
            album_xml_file = iphotodata.get_album_xmlfile(library_path)
            data = iphotodata.get_iphoto_data(album_xml_file)
            msg = "Version %s library with %d images" % (
                data.applicationVersion, len(data.images))
            self.write(msg + '\n')
            if mode == "library":
                # If we just need to check the library, we are done here.
                self.thread_queue.put(("done", (True, mode, msg)))
                return

            # Do the actual export.
            export_folder = su.expand_home_folder(self.export_folder.get())
            args = ['Phoshare.py', '--export', '"' + export_folder + '"']

            options = self.Options()
            options.iphoto = self.iphoto_library.get()
            args.extend(['--iphoto', '"' + options.iphoto + '"'])
            options.export = self.export_folder.get()
            options.dryrun = mode == "dry_run"
            options.albums = self.albums.get()
            if options.albums:
                args.extend(['--albums', '"' + options.albums + '"'])
            options.events = self.events.get()
            if options.events:
                args.extend(['--events', '"' + options.events + '"'])
            options.smarts = self.smarts.get()
            if options.smarts:
                args.extend(['--smarts', '"' + options.smarts + '"'])
            options.foldertemplate = unicode(self.foldertemplate.get())
            if options.foldertemplate:
                args.extend(['--foldertemplate', '"' +
                             options.foldertemplate + '"'])
            options.nametemplate = unicode(self.nametemplate.get())
            if options.nametemplate:
                args.extend(['--nametemplate', '"' +
                             options.nametemplate + '"'])
            options.captiontemplate = unicode(self.captiontemplate.get())
            if options.captiontemplate:
                args.extend(['--captiontemplate', '"' +
                             options.captiontemplate + '"'])
            options.ignore = []  # TODO
            options.update = self.update_var.get() == 1
            if options.update:
                args.append('--update')
            options.delete = self.delete_var.get() == 1
            if options.delete:
                args.append('--delete')
            options.originals = self.originals_var.get() == 1
            if options.originals:
                args.append('--originals')
            options.link = self.link_var.get() == 1
            if options.link:
                args.append('--link')
            options.folderhints = self.folder_hints_var.get() == 1
            if options.folderhints:
                args.append('--folderhints')
            options.faces = self.faces_var.get() == 1
            if options.faces:
                args.append('--faces')
            options.face_keywords = self.face_keywords_var.get() == 1
            if options.face_keywords:
                args.append('--face_keywords')
            if self.iptc_all_var.get() == 1:
                options.iptc = 2
                args.append('--iptcall')
            elif self.iptc_var.get() == 1:
                options.iptc = 1
                args.append('--iptc')
            else:
                options.iptc = 0
            options.gps = self.gps_var.get()
            if options.gps:
                args.append('--gps')
            options.facealbums = self.face_albums_var.get() == 1
            if options.facealbums:
                args.append('--facealbums')
            options.facealbum_prefix = self.face_albums_text.get()
            if options.facealbum_prefix:
                args.append('--facealbum_prefix')

            exclude = None # TODO

            options.save()
            print " ".join(args)

            self.logging_handler.setLevel(logging.DEBUG if self.verbose_var.get() else logging.INFO)
            self.active_library = phoshare_main.ExportLibrary(export_folder)
            phoshare_main.export_iphoto(self.active_library, data, exclude,
                                        options)
            self.thread_queue.put(("done", (True, mode, '')))
        except Exception, e:  # IGNORE:W0703
            self.thread_queue.put(("done",
                                   (False, mode,
                                    str(e) + '\n\n' + traceback.format_exc())))
示例#5
0
def run_phoshare(cmd_args):
    """main routine for phoshare."""
    parser = get_option_parser()
    (options, args) = parser.parse_args(cmd_args)
    if len(args) != 0:
        parser.error("Found some unrecognized arguments on the command line.")

    if options.version:
        print '%s %s' % (phoshare.phoshare_version.PHOSHARE_VERSION,
                         phoshare.phoshare_version.PHOSHARE_BUILD)
        return 1

    if options.iptc > 0 and not exiftool.check_exif_tool():
        print >> sys.stderr, ("Exiftool is needed for the --itpc or --iptcall" +
          " options.")
        return 1

    if options.size and options.link:
        parser.error("Cannot use --size and --link together.")

    if not options.iphoto:
        parser.error("Need to specify the iPhoto library with the --iphoto "
                     "option.")

    if options.export or options.picasaweb or options.checkalbumsize:
        if not (options.albums or options.events or options.smarts or
                options.facealbums):
            parser.error("Need to specify at least one event, album, or smart "
                         "album for exporting, using the -e, -a, or -s "
                         "options.")
    else:
        parser.error("No action specified. Use --export to export from your "
                     "iPhoto library.")

    if options.picasaweb:
        if options.picasapassword:
            google_password = options.picasapassword
        else:
            google_password = getpass.getpass('Google password for %s: ' %
                                              options.picasaweb)

    if options.ratings:
        options.ratings = [int(r) for r in options.ratings.split(",")]

    if options.reverse:
        if not options.dryrun:
            su.pout(u"Turning on dryrun mode because of --reverse option.")
        options.dryrun = True

    logging_handler = logging.StreamHandler()
    logging_handler.setLevel(logging.DEBUG if options.verbose else logging.INFO)
    _logger.addHandler(logging_handler)

    album_xml_file = iphotodata.get_album_xmlfile(
        su.expand_home_folder(options.iphoto))
    if options.omitdatabasefile:
        album_sql_file=""
    else:
        album_sql_file = iphotodata.get_album_sqlfile(
            su.expand_home_folder(options.iphoto))
            
    data = iphotodata.get_iphoto_data(album_xml_file, album_sql_file, ratings=options.ratings,
                                       verbose=options.verbose, aperture=options.aperture)
    if options.originals and options.export:
        data.load_aperture_originals()
        
    options.aperture = data.aperture and not data.aperture_data
    options.foldertemplate = unicode(options.foldertemplate)
    options.nametemplate = unicode(options.nametemplate)
    options.captiontemplate = unicode(options.captiontemplate)

    if options.checkalbumsize:
        data.checkalbumsizes(int(options.checkalbumsize))

    if options.export:
        album = ExportLibrary(su.expand_home_folder(options.export))
        export_iphoto(album, data, options.exclude, options)
    if options.picasaweb:
        try:
            import phoshare.picasaweb as picasaweb
            albums = picasaweb.PicasaAlbums(options.picasaweb, google_password)
            export_iphoto(albums, data, options.exclude, options)
        except ImportError:
            su.perr('Sorry, this version of Phoshare does not support uploading to PicasaWeb.')
示例#6
0
def main():
    """main routine for phoshare."""
    parser = get_option_parser()
    (options, args) = parser.parse_args()
    if len(args) != 0:
        parser.error("Found some unrecognized arguments on the command line.")

    if options.version:
        print '%s %s' % (phoshare.phoshare_version.PHOSHARE_VERSION,
                         phoshare.phoshare_version.PHOSHARE_BUILD)
        return 1

    if options.iptc > 0 and not exiftool.check_exif_tool():
        print >> sys.stderr, ("Exiftool is needed for the --itpc or --iptcall" +
          " options.")
        return 1

    if options.size and options.link:
        parser.error("Cannot use --size and --link together.")

    if not options.iphoto:
        parser.error("Need to specify the iPhoto library with the --iphoto "
                     "option.")

    if options.export or options.picasaweb or options.checkalbumsize:
        if not (options.albums or options.events or options.smarts or
                options.facealbums):
            parser.error("Need to specify at least one event, album, or smart "
                         "album for exporting, using the -e, -a, or -s "
                         "options.")
    else:
        parser.error("No action specified. Use --export to export from your "
                     "iPhoto library.")

    if options.picasaweb:
        if options.picasapassword:
            google_password = options.picasapassword
        else:
            google_password = getpass.getpass('Google password for %s: ' %
                                              options.picasaweb)

    logging_handler = logging.StreamHandler()
    logging_handler.setLevel(logging.DEBUG if options.verbose else logging.INFO)
    _logger.addHandler(logging_handler)

    album_xml_file = iphotodata.get_album_xmlfile(
        su.expand_home_folder(options.iphoto))
    data = iphotodata.get_iphoto_data(album_xml_file)
    if data.aperture:
        if options.originals:
            data.load_aperture_originals()
        check_aperture_mode(options, parser)
 
    options.aperture = data.aperture
    options.foldertemplate = unicode(options.foldertemplate)
    options.nametemplate = unicode(options.nametemplate)
    options.captiontemplate = unicode(options.captiontemplate)

    if options.checkalbumsize:
        data.checkalbumsizes(int(options.checkalbumsize))

    if options.export:
        album = ExportLibrary(su.expand_home_folder(options.export))
        export_iphoto(album, data, options.exclude, options)
    if options.picasaweb:
        albums = picasaweb.PicasaAlbums(options.picasaweb,
                                        google_password)
        export_iphoto(albums, data, options.exclude, options)
示例#7
0
def run_phoshare(cmd_args):
    """main routine for phoshare."""
    parser = get_option_parser()
    (options, args) = parser.parse_args(cmd_args)
    if len(args) != 0:
        parser.error("Found some unrecognized arguments on the command line.")

    if options.version:
        print '%s %s' % (phoshare.phoshare_version.PHOSHARE_VERSION,
                         phoshare.phoshare_version.PHOSHARE_BUILD)
        return 1

    if options.iptc > 0 and not exiftool.check_exif_tool():
        print >> sys.stderr, ("Exiftool is needed for the --itpc or --iptcall" +
          " options.")
        return 1

    if options.size and options.link:
        parser.error("Cannot use --size and --link together.")

    if not options.iphoto:
        parser.error("Need to specify the iPhoto library with the --iphoto "
                     "option.")

    if options.export or options.picasaweb or options.checkalbumsize:
        if not (options.albums or options.events or options.smarts or
                options.facealbums):
            parser.error("Need to specify at least one event, album, or smart "
                         "album for exporting, using the -e, -a, or -s "
                         "options.")
    else:
        parser.error("No action specified. Use --export to export from your "
                     "iPhoto library.")

    if options.picasaweb:
        if options.picasapassword:
            google_password = options.picasapassword
        else:
            google_password = getpass.getpass('Google password for %s: ' %
                                              options.picasaweb)

    if options.ratings:
        options.ratings = [int(r) for r in options.ratings.split(",")]

    if options.reverse:
        if not options.dryrun:
            su.pout(u"Turning on dryrun mode because of --reverse option.")
        options.dryrun = True

    logging_handler = logging.StreamHandler()
    logging_handler.setLevel(logging.DEBUG if options.verbose else logging.INFO)
    _logger.addHandler(logging_handler)

    album_xml_file = iphotodata.get_album_xmlfile(
        su.expand_home_folder(options.iphoto))
    album_sql_file = iphotodata.get_album_sqlfile(
        su.expand_home_folder(options.iphoto))
    data = iphotodata.get_iphoto_data(album_xml_file, album_sql_file, ratings=options.ratings,
                                       verbose=options.verbose, aperture=options.aperture)
    if options.originals and options.export:
        data.load_aperture_originals()
        
    options.aperture = data.aperture and not data.aperture_data
    options.foldertemplate = unicode(options.foldertemplate)
    options.nametemplate = unicode(options.nametemplate)
    options.captiontemplate = unicode(options.captiontemplate)

    if options.checkalbumsize:
        data.checkalbumsizes(int(options.checkalbumsize))

    if options.export:
        album = ExportLibrary(su.expand_home_folder(options.export))
        export_iphoto(album, data, options.exclude, options)
    if options.picasaweb:
        try:
            import phoshare.picasaweb as picasaweb
            albums = picasaweb.PicasaAlbums(options.picasaweb, google_password)
            export_iphoto(albums, data, options.exclude, options)
        except ImportError:
            su.perr('Sorry, this version of Phoshare does not support uploading to PicasaWeb.')