コード例 #1
0
ファイル: __init__.py プロジェクト: peircej/jbrout
    def export(self, list):
        from winexport import Windowexport

        ec = ExportConf(self.conf)

        pathXsl = os.path.join(os.path.dirname(__file__), "xsl")
        XSL = [i for i in os.listdir(pathXsl) if i[0] != "."]

        window_export = Windowexport(ec, "%d photos" % len(list), list, XSL)

        type = window_export.loop()[0]
        if type:
            # so save conf back to conf object !
            ec.save()

            # CONF WAS SAVED in the window
            # so the results are in ec[type+".*"]

            # get the commons
            resize = ec[type + ".resize"]
            percent = ec[type + ".percent"]
            quality = ec[type + ".quality"]
            maxside = ec[type + ".maxside"]
            order = ec[type + ".order"]
            metadata = ec[type + ".metadata"]

            delCom = False
            delTags = False
            keepInfo = True
            if metadata == 4:
                keepInfo = False
            elif metadata == 3:
                delCom = True
                delTags = True
            elif metadata == 2:
                delTags = True
            elif metadata == 1:
                delCom = True

            # 0:Keep, 1:Del comment, 2:Del tags, 3:Del comment & tags, 4:Del all

            if type == "CA":
                msg = _("Export to archive")
                #==================================================================
                path = ec["CA.folder"]
                if os.path.isdir(path):
                    destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                    print "Opening Archive"
                    if ec["CA.type"] in ['tar', 'tbz', 'tgz']:
                        if ec["CA.type"] == 'tar':
                            archMode = 'w'
                        elif ec["CA.type"] == 'tbz':
                            archMode = 'w:bz2'
                        else:
                            archMode = 'w:gz'
                        archive = tarfile.open(os.path.join(path, ("Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S") + '.' + ec["CA.type"])), archMode)
                    else:
                        archive = zipfile.ZipFile(os.path.join(path, ("Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S") + '.zip')), "w")
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "FS":
                msg = _("Export to folder")
                #==================================================================
                path = ec["FS.folder"]
                if os.path.isdir(path):
                    destination = unicode(path + "/Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S"))
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "HG":
                msg = _("Export as a Html Gallery")
                #==================================================================
                path = ec["HG.folder"]
                if os.path.isdir(path):
                    destg = unicode(path + "/Html " + time.strftime("%Y-%m-%d, %H-%M-%S"))

                    # prepare the destination
                    os.mkdir(destg)

                    destination = os.path.join(destg, "img")
                    dirThumbs = os.path.join(destg, "thumbs")

                    if not os.path.isdir(destination):
                        os.mkdir(destination)
                    if not os.path.isdir(dirThumbs):
                        os.mkdir(dirThumbs)

                    # and prepare le xml
                    nodeAlbum = Element("export")

                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "PW":
                msg = _("Export to PicasaWeb")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    picasa = PicasaWeb(ec["PW.login"], uncrypt(ec["PW.password"]))
                    if picasa:
                        album = picasa.createAlbum("Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S"), public=(ec["PW.privacy"] == 0))
                    else:
                        raise PicasaException(_("Sorry, you can't upload to picasaweb (python import error)"))
                except Exception, err:
                    self.MessageBox(_("Upload error : ") + str(err))
                    return False


            elif type == "FR":
                msg = _("Export to Flickr")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                flickr_uploader = FlickrUploader(self.conf, self.validateWin)

            elif type == "SM":
                msg = _("Export to Email")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                filesToSend = []

            elif type == "FT":
                msg = _("Export to FTP")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    ftp = ftplib.FTP(ec["FT.ftp"], ec["FT.login"], uncrypt(ec["FT.password"]))
                    try:
                        ftp.cwd(ec["FT.path"])
                    except:
                        ftp.mkd(ec["FT.path"])
                        ftp.cwd(ec["FT.path"])
                except Exception, err:
                    self.MessageBox(_("FTP error : ") + str(err))
                    return False
コード例 #2
0
ファイル: __init__.py プロジェクト: peircej/jbrout
    def export(self, list):
        from winexport import Windowexport

        ec = ExportConf(self.conf)

        pathXsl = os.path.join(os.path.dirname(__file__), "xsl")
        XSL = [i for i in os.listdir(pathXsl) if i[0] != "."]

        window_export = Windowexport(ec, "%d photos" % len(list), list, XSL)

        type = window_export.loop()[0]
        if type:
            # so save conf back to conf object !
            ec.save()

            # CONF WAS SAVED in the window
            # so the results are in ec[type+".*"]

            # get the commons
            resize = ec[type + ".resize"]
            percent = ec[type + ".percent"]
            quality = ec[type + ".quality"]
            maxside = ec[type + ".maxside"]
            order = ec[type + ".order"]
            metadata = ec[type + ".metadata"]

            delCom = False
            delTags = False
            keepInfo = True
            if metadata == 4:
                keepInfo = False
            elif metadata == 3:
                delCom = True
                delTags = True
            elif metadata == 2:
                delTags = True
            elif metadata == 1:
                delCom = True

            # 0:Keep, 1:Del comment, 2:Del tags, 3:Del comment & tags, 4:Del all

            if type == "CA":
                msg = _("Export to archive")
                #==================================================================
                path = ec["CA.folder"]
                if os.path.isdir(path):
                    destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                    print "Opening Archive"
                    if ec["CA.type"] in ['tar', 'tbz', 'tgz']:
                        if ec["CA.type"] == 'tar':
                            archMode = 'w'
                        elif ec["CA.type"] == 'tbz':
                            archMode = 'w:bz2'
                        else:
                            archMode = 'w:gz'
                        archive = tarfile.open(
                            os.path.join(path,
                                         ("Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S") +
                                          '.' + ec["CA.type"])), archMode)
                    else:
                        archive = zipfile.ZipFile(
                            os.path.join(path,
                                         ("Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S") +
                                          '.zip')), "w")
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "FS":
                msg = _("Export to folder")
                #==================================================================
                path = ec["FS.folder"]
                if os.path.isdir(path):
                    destination = unicode(path + "/Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S"))
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "HG":
                msg = _("Export as a Html Gallery")
                #==================================================================
                path = ec["HG.folder"]
                if os.path.isdir(path):
                    destg = unicode(path + "/Html " +
                                    time.strftime("%Y-%m-%d, %H-%M-%S"))

                    # prepare the destination
                    os.mkdir(destg)

                    destination = os.path.join(destg, "img")
                    dirThumbs = os.path.join(destg, "thumbs")

                    if not os.path.isdir(destination):
                        os.mkdir(destination)
                    if not os.path.isdir(dirThumbs):
                        os.mkdir(dirThumbs)

                    # and prepare le xml
                    nodeAlbum = Element("export")

                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "PW":
                msg = _("Export to PicasaWeb")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    picasa = PicasaWeb(ec["PW.login"],
                                       uncrypt(ec["PW.password"]))
                    if picasa:
                        album = picasa.createAlbum(
                            "Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S"),
                            public=(ec["PW.privacy"] == 0))
                    else:
                        raise PicasaException(
                            _("Sorry, you can't upload to picasaweb (python import error)"
                              ))
                except Exception, err:
                    self.MessageBox(_("Upload error : ") + str(err))
                    return False

            elif type == "FR":
                msg = _("Export to Flickr")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                flickr_uploader = FlickrUploader(self.conf, self.validateWin)

            elif type == "SM":
                msg = _("Export to Email")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                filesToSend = []

            elif type == "FT":
                msg = _("Export to FTP")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    ftp = ftplib.FTP(ec["FT.ftp"], ec["FT.login"],
                                     uncrypt(ec["FT.password"]))
                    try:
                        ftp.cwd(ec["FT.path"])
                    except:
                        ftp.mkd(ec["FT.path"])
                        ftp.cwd(ec["FT.path"])
                except Exception, err:
                    self.MessageBox(_("FTP error : ") + str(err))
                    return False
コード例 #3
0
    def initFromConf(self,conf):
        self.__conf = conf

        if conf["type"] == "FS":
            self.nbExport.set_current_page(0)
        elif conf["type"] == "HG":
            self.nbExport.set_current_page(1)
        elif conf["type"] == "PW":
            self.nbExport.set_current_page(2)
        elif conf["type"] == "FR":
            self.nbExport.set_current_page(3)
        elif conf["type"] == "SM":
            self.nbExport.set_current_page(4)
        elif conf["type"] == "FT":
            self.nbExport.set_current_page(5)
        elif conf["type"] == "CA":
            self.nbExport.set_current_page(6)
        else:
            print "bad export type in conf : %s" % str(conf["type"])
            self.nbExport.set_current_page(0)

        self.tbFolderA.set_text( conf["CA.folder"] )
        if conf["CA.type"] == "tar":
            self.cbTypeA.set_active(0)
        elif conf["CA.type"] == "tbz":
            self.cbTypeA.set_active(1)
        elif conf["CA.type"] == "tgz":
            self.cbTypeA.set_active(2)
        else: # Use zip as the default/failsafe
            self.cbTypeA.set_active(3)

        self.tbFolderF.set_text( conf["FS.folder"] )

        self.tbFolderH.set_text( conf["HG.folder"] )
        self.cbTemplate.set_active( conf["HG.template"] )

        self.tbLoginPW.set_text( conf["PW.login"] )
        self.tbPasswordPW.set_text( uncrypt(conf["PW.password"]) )
        if (bool(conf["PW.privacy"])): self.rbPrivatePW.set_active(1)
        else: self.rbPublicPW.set_active(1)

        if (bool(conf["FR.public"])): self.rbPublicFR.set_active(1)
        else: self.rbPrivateFR.set_active(1)
        if (bool(conf["FR.friends"])): self.cbFriendsFR.set_active(1)
        else: self.cbFriendsFR.set_active(0)
        if (bool(conf["FR.family"])): self.cbFamilyFR.set_active(1)
        else: self.cbFamilyFR.set_active(0)
        if (bool(conf["FR.same_privacy"])): self.cbSelectAllFR.set_active(1)
        else: self.cbSelectAllFR.set_active(0)

        self.tbSmtp.set_text(conf["SM.smtp"])
        self.spPortSM.set_value(int(conf["SM.port"]))
        if (bool(conf["SM.auth"])):
            self.cbAuthSM.set_active(True)
            self.tbUserSM.set_sensitive(True)
            self.tbPasswordSM.set_sensitive(True)
        else:
            self.cbAuthSM.set_active(False)
            self.tbUserSM.set_sensitive(False)
            self.tbPasswordSM.set_sensitive(False)
        self.tbUserSM.set_text(conf["SM.username"])
        self.tbPasswordSM.set_text(uncrypt(conf["SM.password"]))
        self.cbSecurity.set_active(int(conf["SM.security"]))
        self.tbTo.set_text( conf["SM.to"] )
        self.tbFrom.set_text( conf["SM.from"] )
        self.tbSubject.set_text( conf["SM.subject"] )
        self.tbMessage.set_text( conf["SM.message"] )

        self.tbFtp.set_text( conf["FT.ftp"] )
        self.tbLoginFT.set_text( conf["FT.login"] )
        self.tbPasswordFT.set_text( uncrypt(conf["FT.password"]) )
        self.tbPath.set_text( conf["FT.path"] )
コード例 #4
0
ファイル: __init__.py プロジェクト: peircej/jbrout
class Plugin(JPlugin):
    """ Multi export plugin"""

    __author__ = "manatlan"
    __version__ = "0.10"

    # def menuEntries(self,l):
    #    return [(3000,_("Export to"),False,self.export,None)]

    @JPlugin.Entry.PhotosProcess(_("Export to"), order=3000, alter=False)
    def export(self, list):
        from winexport import Windowexport

        ec = ExportConf(self.conf)

        pathXsl = os.path.join(os.path.dirname(__file__), "xsl")
        XSL = [i for i in os.listdir(pathXsl) if i[0] != "."]

        window_export = Windowexport(ec, "%d photos" % len(list), list, XSL)

        type = window_export.loop()[0]
        if type:
            # so save conf back to conf object !
            ec.save()

            # CONF WAS SAVED in the window
            # so the results are in ec[type+".*"]

            # get the commons
            resize = ec[type + ".resize"]
            percent = ec[type + ".percent"]
            quality = ec[type + ".quality"]
            maxside = ec[type + ".maxside"]
            order = ec[type + ".order"]
            metadata = ec[type + ".metadata"]

            delCom = False
            delTags = False
            keepInfo = True
            if metadata == 4:
                keepInfo = False
            elif metadata == 3:
                delCom = True
                delTags = True
            elif metadata == 2:
                delTags = True
            elif metadata == 1:
                delCom = True

            # 0:Keep, 1:Del comment, 2:Del tags, 3:Del comment & tags, 4:Del all

            if type == "CA":
                msg = _("Export to archive")
                #==================================================================
                path = ec["CA.folder"]
                if os.path.isdir(path):
                    destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                    print "Opening Archive"
                    if ec["CA.type"] in ['tar', 'tbz', 'tgz']:
                        if ec["CA.type"] == 'tar':
                            archMode = 'w'
                        elif ec["CA.type"] == 'tbz':
                            archMode = 'w:bz2'
                        else:
                            archMode = 'w:gz'
                        archive = tarfile.open(
                            os.path.join(path,
                                         ("Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S") +
                                          '.' + ec["CA.type"])), archMode)
                    else:
                        archive = zipfile.ZipFile(
                            os.path.join(path,
                                         ("Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S") +
                                          '.zip')), "w")
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "FS":
                msg = _("Export to folder")
                #==================================================================
                path = ec["FS.folder"]
                if os.path.isdir(path):
                    destination = unicode(path + "/Jbrout " +
                                          time.strftime("%Y-%m-%d, %H-%M-%S"))
                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "HG":
                msg = _("Export as a Html Gallery")
                #==================================================================
                path = ec["HG.folder"]
                if os.path.isdir(path):
                    destg = unicode(path + "/Html " +
                                    time.strftime("%Y-%m-%d, %H-%M-%S"))

                    # prepare the destination
                    os.mkdir(destg)

                    destination = os.path.join(destg, "img")
                    dirThumbs = os.path.join(destg, "thumbs")

                    if not os.path.isdir(destination):
                        os.mkdir(destination)
                    if not os.path.isdir(dirThumbs):
                        os.mkdir(dirThumbs)

                    # and prepare le xml
                    nodeAlbum = Element("export")

                else:
                    self.MessageBox(_("The selected path doesn't exists !"))
                    return False

            elif type == "PW":
                msg = _("Export to PicasaWeb")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    picasa = PicasaWeb(ec["PW.login"],
                                       uncrypt(ec["PW.password"]))
                    if picasa:
                        album = picasa.createAlbum(
                            "Jbrout " + time.strftime("%Y-%m-%d, %H-%M-%S"),
                            public=(ec["PW.privacy"] == 0))
                    else:
                        raise PicasaException(
                            _("Sorry, you can't upload to picasaweb (python import error)"
                              ))
                except Exception, err:
                    self.MessageBox(_("Upload error : ") + str(err))
                    return False

            elif type == "FR":
                msg = _("Export to Flickr")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                flickr_uploader = FlickrUploader(self.conf, self.validateWin)

            elif type == "SM":
                msg = _("Export to Email")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))
                filesToSend = []

            elif type == "FT":
                msg = _("Export to FTP")
                #==================================================================
                destination = unicode(tempfile.mkdtemp(".tmp", "jbrout"))

                try:
                    ftp = ftplib.FTP(ec["FT.ftp"], ec["FT.login"],
                                     uncrypt(ec["FT.password"]))
                    try:
                        ftp.cwd(ec["FT.path"])
                    except:
                        ftp.mkd(ec["FT.path"])
                        ftp.cwd(ec["FT.path"])
                except Exception, err:
                    self.MessageBox(_("FTP error : ") + str(err))
                    return False

            if order == 1:  # olders first
                list.reverse()

            try:
                try:

                    if not os.path.isdir(
                            destination):  # if it was not create before
                        os.mkdir(destination)

                    for photo in list:
                        self.showProgress(list.index(photo), len(list), msg)

                        if resize == 0:  # no resize
                            file = photo.copyTo(destination,
                                                keepInfo=keepInfo,
                                                delCom=delCom,
                                                delTags=delTags)
                        elif resize == 1:  # resize
                            file = photo.copyTo(destination,
                                                resize=(float(percent / 100),
                                                        quality))
                        elif resize == 2:  # max side
                            file = photo.copyTo(destination,
                                                resize=(int(maxside), quality))

                        if type == "CA":
                            # TODO: add file to archive
                            print "Adding file '%s'" % file
                            if ec["CA.type"] in ['tar', 'tbz', 'tgz']:
                                archive.add(
                                    file,
                                    os.path.basename(file).encode("utf_8"))
                            else:
                                archive.write(
                                    file,
                                    os.path.basename(file).encode("utf_8"))
                        elif type == "FS":
                            # nothing to do more
                            pass
                        elif type == "HG":
                            # create a img node
                            nodeImg = Element("img")

                            # and create the thumb
                            dest = os.path.join(dirThumbs, photo.name)
                            pb = photo.getThumb()
                            pb.save(dest, "jpeg", {"quality": "80"})

                            # and fill the node
                            nodeImg.set("src", "img/" + photo.name)
                            nodeImg.set("mini", "thumbs/" + photo.name)

                            nodeImg.set("albumComment",
                                        photo.getParent().comment)
                            nodeImg.set("album", photo.getParent().name)
                            nodeImg.set("comment", photo.comment)
                            nodeImg.set("tags", ", ".join(photo.tags))
                            nodeImg.set("hdate",
                                        cd2rd(photo.date))  # human date ;-)
                            nodeImg.set("date", photo.date)

                            # and add it to the album
                            nodeAlbum.append(nodeImg)

                        elif type == "PW":
                            album.uploadPhoto(file,
                                              photo.comment)  # (pycasaweb)
                            # album.uploadPhoto(file)
                        elif type == "FR":
                            err = flickr_uploader.upload(
                                file, photo.comment, photo.tags,
                                window_export.getPrivacyFR(photo))
                            if err: raise Exception(err)
                        elif type == "SM":
                            filesToSend.append(file)
                        elif type == "FT":
                            fid = open(file, 'rb')
                            ftp.storbinary('STOR ' + os.path.basename(file),
                                           fid)

                    # and close the work
                    if type == "CA":
                        # TODO: close archive
                        print "Closing archive"
                        archive.close()
                    elif type == "HG":
                        # finish the work for the html galleyr
                        xml_doc = ElementTree(nodeAlbum)

                        # save a copy of the xml used file for info (can be deleted)
                        fid = open(destg + "/photos.xml", "w")
                        xml_doc.write(fid)
                        fid.close()

                        # applys the xslt transformation
                        xslt_doc = parse(
                            os.path.join(pathXsl, XSL[ec["HG.template"]]))
                        nodeParams = xslt_doc.xpath(
                            "//xsl:param",
                            namespaces={
                                "xsl": "http://www.w3.org/1999/XSL/Transform"
                            })

                        p = 1
                        while True:

                            # the worst way to pass a param ;-)
                            nodeParams[0].text = str(p)
                            # ~ nodeParams[1].text="8"

                            style = XSLT(xslt_doc)

                            result = style.apply(xml_doc)
                            page = style.tostring(result)
                            if "body" in page:
                                open(destg + "/page%d.html" % p,
                                     "w").write(page)
                                p += 1
                            else:
                                break
                    elif type == "SM":
                        fro = ec["SM.from"]

                        if "," in ec["SM.to"]:
                            to = ec["SM.to"].split(",")
                        elif ";" in ec["SM.to"]:
                            to = ec["SM.to"].split(";")
                        else:
                            to = [
                                ec["SM.to"],
                            ]

                        text = ec["SM.message"]
                        subject = ec["SM.subject"]
                        server = ec["SM.smtp"]
                        secTypes = ['none', 'ssl', 'start tls']
                        security = secTypes[int(ec["SM.security"])]
                        port = int(ec["SM.port"])
                        auth = bool(ec["SM.auth"])
                        username = ec["SM.username"].encode("utf_8")
                        password = uncrypt(ec["SM.password"]).encode("utf_8")

                        sendMail(fro, to, subject, text, filesToSend, server,
                                 security, port, auth, username, password)
                    elif type == "FT":
                        ftp.quit()

                    if destination.endswith(".tmp"):  # it's a temp dir
                        shutil.rmtree(destination)

                except Exception, err:
                    self.MessageBox(_("Plugin error : ") + str(err))

            finally:
                self.showProgress()