示例#1
0
    def __init__(self):
        Progresser.__init__(self)
        #Job.__init__(self)
        self.simulate = True
        self.count_errors = 0
        #self.count_warnings = 0
        self.count_newer = 0
        self.count_same = 0
        self.count_delete_file = 0
        self.count_update_file = 0
        self.count_copy_file = 0
        self.count_delete_dir = 0
        #self.count_update_dir = 0
        self.count_copy_dir = 0

        self.done_same = 0
        self.done_delete_file = 0
        self.done_update_file = 0
        self.done_copy_file = 0
        self.done_delete_dir = 0
        #self.done_update_dir = 0
        self.done_copy_dir = 0
        self.projects = []

        self._statusAnalysing = _("keep %d, update %d (%d newer), "
                                  "copy %d, delete %d files.")

        self._statusDoing = _("kept %d, updated %d, copied %d,"
                              " deleted %d files.")
示例#2
0
    def getSummary(self):
        l=[]
        if self.count_same:
            l.append( _("%d files up-to-date") % self.count_same)
        if self.count_delete_file or self.count_delete_dir:
            s = _("%d files and %d directories ")
            if self.simulate:
                s += _("to remove")
            else:
                s += _("were removed")

            l.append(s % (self.count_delete_file,
                          self.count_delete_dir))
        
        #s = _("%d files and %d directories ")
        if self.count_update_file:
            s = _("%d files ")
            if self.simulate:
                s += _("to update")
            else:
                s += _("were updated")
            l.append(s % self.count_update_file)

        if self.count_copy_file or self.count_copy_dir:
            s = _("%d files and %d directories ")
            if self.simulate:
                s += _("to copy")
            else:
                s += _("were copied")
            l.append(s % (self.count_copy_file, self.count_copy_dir))
        
        #if self.count_newer:
        #l += Job.getSummary(self)
        return "\n".join(l)
示例#3
0
    def getSummary(self):
        l = []
        if self.count_same:
            l.append(_("%d files up-to-date") % self.count_same)
        if self.count_delete_file or self.count_delete_dir:
            s = _("%d files and %d directories ")
            if self.simulate:
                s += _("to remove")
            else:
                s += _("were removed")

            l.append(s % (self.count_delete_file, self.count_delete_dir))

        #s = _("%d files and %d directories ")
        if self.count_update_file:
            s = _("%d files ")
            if self.simulate:
                s += _("to update")
            else:
                s += _("were updated")
            l.append(s % self.count_update_file)

        if self.count_copy_file or self.count_copy_dir:
            s = _("%d files and %d directories ")
            if self.simulate:
                s += _("to copy")
            else:
                s += _("were copied")
            l.append(s % (self.count_copy_file, self.count_copy_dir))

        #if self.count_newer:
        #l += Job.getSummary(self)
        return "\n".join(l)
示例#4
0
    def __init__(self):
        Progresser.__init__(self)
        #Job.__init__(self)
        self.simulate=True
        self.count_errors = 0
        #self.count_warnings = 0
        self.count_newer = 0
        self.count_same = 0
        self.count_delete_file = 0
        self.count_update_file = 0
        self.count_copy_file = 0
        self.count_delete_dir = 0
        #self.count_update_dir = 0
        self.count_copy_dir = 0
        
        self.done_same = 0
        self.done_delete_file = 0
        self.done_update_file = 0
        self.done_copy_file = 0
        self.done_delete_dir = 0
        #self.done_update_dir = 0
        self.done_copy_dir = 0
        self.projects=[]

        self._statusAnalysing = _("keep %d, update %d (%d newer), "
                                  "copy %d, delete %d files.")
        
        self._statusDoing = _("kept %d, updated %d, copied %d,"
                              " deleted %d files.")
示例#5
0
 def copy_file(self, src, target):
     #self.verbose(_("copy file %s to %s") % (src,target))
     if self.job.simulate:
         self.verbose(_("Must copy %s"), target)
         self.job.count_copy_file += 1
         return
     #self.notice(_("copy file %s to %s") % (src,target))
     self.verbose(_("Copying %s"), target)
     try:
         shutil.copyfile(src, target)
     except IOError, e:
         self.error("copyfile('%s','%s') failed", src, target)
         return
示例#6
0
 def copy_file(self,src,target):
     #self.verbose(_("copy file %s to %s") % (src,target))
     if self.job.simulate:
         self.verbose(_("Must copy %s"), target)
         self.job.count_copy_file += 1
         return
     #self.notice(_("copy file %s to %s") % (src,target))
     self.verbose(_("Copying %s"), target)
     try:
         shutil.copyfile(src, target)
     except IOError,e:
         self.error("copyfile('%s','%s') failed",src,target)
         return
示例#7
0
    def delete_dir(self, name):
        if self.job.simulate:
            self.verbose(_("Must remove %s") % name)
            self.job.count_delete_dir += 1
            return

        self.verbose(_("Removing %s") % name)
        for fn in os.listdir(name):
            self.delete_it(os.path.join(name, fn))

        try:
            os.rmdir(name)
        except IOError, e:
            self.error("os.rmdir('%s') failed", name)
示例#8
0
 def delete_dir(self,name):
     if self.job.simulate:
         self.verbose(_("Must remove %s") % name)
         self.job.count_delete_dir += 1
         return
     
     self.verbose(_("Removing %s") % name)
     for fn in os.listdir(name):
         self.delete_it(os.path.join(name,fn))
         
     try:
         os.rmdir(name)
     except IOError,e:
         self.error("os.rmdir('%s') failed",name)
示例#9
0
    def abort(self,msg=None):
        if msg is None:
            msg = _("Aborted")
##         if msg is not None:
##             self._status = msg
        if not self._done:
            self._done = True
            self.session.toolkit.onJobAbort(self,msg)
示例#10
0
    def delete_file(self,name):
        if self.job.simulate:
            self.verbose(_("Must delete %s"),name)
            self.job.count_delete_file += 1
            return

        self.verbose(_("Deleting %s"),name)
        if win32file:
            filemode = win32file.GetFileAttributesW(name)
            try:
                win32file.SetFileAttributesW(
                    name, filemode & \
                    ~win32file.FILE_ATTRIBUTE_READONLY & \
                    ~win32file.FILE_ATTRIBUTE_HIDDEN & \
                    ~win32file.FILE_ATTRIBUTE_SYSTEM)
            except win32file.error,e:
                self.error(name+" : SetFileAttributesW() failed")
示例#11
0
    def delete_file(self, name):
        if self.job.simulate:
            self.verbose(_("Must delete %s"), name)
            self.job.count_delete_file += 1
            return

        self.verbose(_("Deleting %s"), name)
        if win32file:
            filemode = win32file.GetFileAttributesW(name)
            try:
                win32file.SetFileAttributesW(
                    name, filemode & \
                    ~win32file.FILE_ATTRIBUTE_READONLY & \
                    ~win32file.FILE_ATTRIBUTE_HIDDEN & \
                    ~win32file.FILE_ATTRIBUTE_SYSTEM)
            except win32file.error, e:
                self.error(name + " : SetFileAttributesW() failed")
示例#12
0
 def copy_dir(self,src,target):
     if self.job.simulate:
         self.job.count_copy_dir += 1
     else:
         self.verbose(_("Creating directory %s"), target)
         try:
             os.mkdir(target)
         except OSError,e:
             self.error("os.mkdir('%s') failed",target)
             return
         # self.utime(src,target)
         self.job.done_copy_dir += 1
示例#13
0
 def copy_dir(self, src, target):
     if self.job.simulate:
         self.job.count_copy_dir += 1
     else:
         self.verbose(_("Creating directory %s"), target)
         try:
             os.mkdir(target)
         except OSError, e:
             self.error("os.mkdir('%s') failed", target)
             return
         # self.utime(src,target)
         self.job.done_copy_dir += 1
示例#14
0
    def __init__(self,job,src,target,recurse=False,ignorePatterns=None):
        Progresser.__init__(self)
        #self.app=app
        self.job=job
        self.src = unicode(src)
        self.target = unicode(target)
        #self.simulate = simulate
        self.recurse = recurse
        self.ignorePatterns = ignorePatterns
        
        self.ignore_times = False        
        self.modify_window = 2

        if not os.path.exists(self.src) \
              and not os.path.ismount(self.src):
            raise OperationFailed(
                _("Source directory '%s' doesn't exist.") % self.src)

        if not os.path.exists(self.target) \
              and not os.path.ismount(self.target):
            raise OperationFailed(
                _("Target directory '%s' doesn't exist.") % self.target)
示例#15
0
    def __init__(self, job, src, target, recurse=False, ignorePatterns=None):
        Progresser.__init__(self)
        #self.app=app
        self.job = job
        self.src = unicode(src)
        self.target = unicode(target)
        #self.simulate = simulate
        self.recurse = recurse
        self.ignorePatterns = ignorePatterns

        self.ignore_times = False
        self.modify_window = 2

        if not os.path.exists(self.src) \
              and not os.path.ismount(self.src):
            raise OperationFailed(
                _("Source directory '%s' doesn't exist.") % self.src)

        if not os.path.exists(self.target) \
              and not os.path.ismount(self.target):
            raise OperationFailed(
                _("Target directory '%s' doesn't exist.") % self.target)
示例#16
0
    def run(self):

        if len(self.args) == 0:
            raise UsageError("needs 1 argument")

        self.server = None
        self.dataDir = "."
        self.count_ok = 0
        self.count_nok = 0

        if self.options.host is None:
            raise UsageError("--host must be specified")

        ##         for fn in  self.attach_files:
        ##             if not os.path.exists(fn):
        ##                 raise OperationFailed("File %s does not exist."%fn)

        files = []
        for pattern in self.args:
            files += glob.glob(pattern)

        self.count_todo = len(files)
        if self.count_todo == 0:
            self.notice("Nothing to do: no input files found.")
            return

        if self.options.recipient is None:
            recipients = []
        else:
            recipients = getaddresses([self.options.recipient])

        sender = self.options.sender
        subject = self.options.subject

        """

        if the first input file's name ends with .eml, then this
        becomes the outer message
        

        """
        if files[0].lower().endswith(".eml"):
            self.notice("Reading file %s...", files[0])
            first = email.message_from_file(codecs.open(files[0], "r", self.options.encoding), _class=MyMessage)
            if first.has_key("subject"):
                subject = first["subject"]
                del first["subject"]
                first["subject"] = Header(subject, first.get_charset())

            self.encodeaddrs(first, "from")
            if sender is None:
                sender = first["from"]
            self.encodeaddrs(first, "to", recipients)
            self.encodeaddrs(first, "cc", recipients)
            self.encodeaddrs(first, "bcc", recipients)
            del first["bcc"]

            del files[0]
            self.count_todo -= 1
        else:
            first = None

        if len(files) == 0:
            outer = first
        else:
            # Create the enclosing (outer) message
            outer = MIMEMultipart()
            # outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
            if first is not None:
                first.add_header("Content-Disposition", "inline")
                outer.attach(first)
                for hdr in ("to", "cc"):
                    outer[hdr] = first[hdr]
            outer["subject"] = subject
            outer["from"] = sender
            self.notice("Attaching %d files...", self.count_todo)
            i = 1
            for filename in files:
                self.notice(u"%s (%d/%d)", filename, i, self.count_todo)
                part = self.file2msg(filename)
                # Set the filename parameter
                part.add_header("Content-Disposition", "attachment", filename=os.path.basename(filename))
                outer.attach(part)
                i += 1

        # for part in outer.walk():
        # if recipient is None: recipient=part["To"]
        # if bcc is None: bcc=part["Bcc"]

        if self.options.subject is not None:
            del outer["subject"]
            outer["subject"] = self.options.subject
        # if self.options.sender is not None:
        #    del outer['from']
        #    outer['from'] = self.options.sender
        # del outer['to']
        # outer['to'] = recipient
        # if bcc is not None:
        #    outer['Bcc'] = bcc
        #    print "Bcc:", bcc

        # headers_i18n(outer)

        if len(recipients) == 0:
            for addr in open(opj(self.dataDir, "addrlist.txt")).xreadlines():
                addr = addr.strip()
                if len(addr) != 0 and addr[0] != "#":
                    recipients += getaddresses([addr])

        if not outer.has_key("Subject"):
            raise "Subject header is missing"
        if not outer.has_key("Date"):
            outer["Date"] = email.Utils.formatdate(None, True)

        for k, v in outer.items():
            print k, ":", unicode(v)
        # self.notice(str(outer.keys()))
        self.notice(_("Message size: %d bytes."), len(str(outer)))
        self.notice(_("Send this to %d recipients: %s"), len(recipients), ", ".join([a[1] for a in recipients]))

        sender = parseaddr(unicode(sender))[1]

        # print "sender:", unicode(sender)

        # print outer.as_string(unixfrom=0)

        if not self.confirm("Okay?"):
            return

        self.connect()

        self.sendmsg(outer, sender, recipients)

        self.server.quit()

        self.notice(_("Sent to %d recipients."), self.count_ok)
        if self.count_nok != 0:
            self.notice(_("%d recipients refused."), self.count_nok)
示例#17
0
    def run(self, safely=True, noaction=False):
        #self.session=task.session
        #self.task=task
        #self.maxval=0
        #for p in self.projects:
        #    self.notice(str(p))

        ##         if showProgress:
        ##             def f():
        ##                 for prj in self.projects:
        ##                     self.maxval += prj.countFiles(self)
        ##             Looper(f,_("Counting files...")).runfrom(self)
        ##             #sess.loop(f,_("Counting files..."))
        ##             self.notice(_("Found %d files."), self.maxval)

        if safely:
            self.simulate = True

            ##             def f(task):
            ##                 for p in self.projects:
            ##                     task.runtask(p)
            ##             self.loop(f,_("Analyzing..."),self.maxval)

            for p in self.projects:
                self.notice(_("Analyzing %s ..."), p)
                self.runtask(p)
                p.setMaxVal(p.curval)

            self.notice(self.getSummary())

            if not (self.count_delete_dir \
                 or self.count_delete_file \
                 or self.count_copy_file \
                 or self.count_copy_dir \
                 or self.count_update_file) :
                self.notice(_("Nothing to do"))
                return

            if self.count_newer > 0:
                if not self.confirm(
                    _("%d target files are NEWER! Are you sure?") \
                    % self.count_newer, default=False):
                    return
        else:
            self.notice(self.getSummary())

        if noaction:
            return

        if not self.confirm(_("Start?")):
            return

        self.simulate = False

        ##         def f(task):
        ##             for p in self.projects:
        ##                 task.runtask(p)
        ##         self.loop(f,"Synchronizing",self.maxval)

        for p in self.projects:
            self.notice(_("Synchronizing %s ..."), p)
            self.runtask(p)

        self.notice(self.getSummary())
示例#18
0
 def getStatus(self):
     return _("Working")
示例#19
0
 def getStatus(self):
     # may override
     s = _("%d warnings") % (self.count_warnings) 
     s += ". " + _("%d errors") % (self.count_errors) + "."
     return s
示例#20
0
 def requestAbort(self):
     if self.confirm( _("Are you sure you want to abort?"),
                      default=False):
         raise UserAborted()
     #self._abortRequested=False
     self.toolkit.onTaskResume(self)
示例#21
0
    def run(self):

        if len(self.args) == 0:
            raise UsageError("needs 1 argument")

        self.server = None
        self.dataDir = '.'
        self.count_ok = 0
        self.count_nok = 0

        if self.options.host is None:
            raise UsageError("--host must be specified")

##         for fn in  self.attach_files:
##             if not os.path.exists(fn):
##                 raise OperationFailed("File %s does not exist."%fn)

        files = []
        for pattern in self.args:
            files += glob.glob(pattern)

        self.count_todo = len(files)
        if self.count_todo == 0:
            self.notice("Nothing to do: no input files found.")
            return

        if self.options.recipient is None:
            recipients = []
        else:
            recipients = getaddresses([self.options.recipient])

        sender = self.options.sender
        subject = self.options.subject
        """

        if the first input file's name ends with .eml, then this
        becomes the outer message
        

        """
        if files[0].lower().endswith(".eml"):
            self.notice("Reading file %s...", files[0])
            first = email.message_from_file(codecs.open(
                files[0], "r", self.options.encoding),
                                            _class=MyMessage)
            if first.has_key('subject'):
                subject = first["subject"]
                del first["subject"]
                first["subject"] = Header(subject, first.get_charset())

            self.encodeaddrs(first, 'from')
            if sender is None: sender = first["from"]
            self.encodeaddrs(first, 'to', recipients)
            self.encodeaddrs(first, 'cc', recipients)
            self.encodeaddrs(first, 'bcc', recipients)
            del first['bcc']

            del files[0]
            self.count_todo -= 1
        else:
            first = None

        if len(files) == 0:
            outer = first
        else:
            # Create the enclosing (outer) message
            outer = MIMEMultipart()
            # outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
            if first is not None:
                first.add_header('Content-Disposition', 'inline')
                outer.attach(first)
                for hdr in ('to', 'cc'):
                    outer[hdr] = first[hdr]
            outer['subject'] = subject
            outer['from'] = sender
            self.notice("Attaching %d files...", self.count_todo)
            i = 1
            for filename in files:
                self.notice(u"%s (%d/%d)", filename, i, self.count_todo)
                part = self.file2msg(filename)
                # Set the filename parameter
                part.add_header('Content-Disposition',
                                'attachment',
                                filename=os.path.basename(filename))
                outer.attach(part)
                i += 1

        #for part in outer.walk():
        #if recipient is None: recipient=part["To"]
        #if bcc is None: bcc=part["Bcc"]

        if self.options.subject is not None:
            del outer['subject']
            outer['subject'] = self.options.subject
        #if self.options.sender is not None:
        #    del outer['from']
        #    outer['from'] = self.options.sender
        #del outer['to']
        #outer['to'] = recipient
        #if bcc is not None:
        #    outer['Bcc'] = bcc
        #    print "Bcc:", bcc

        #headers_i18n(outer)

        if len(recipients) == 0:
            for addr in open(opj(self.dataDir, "addrlist.txt")).xreadlines():
                addr = addr.strip()
                if len(addr) != 0 and addr[0] != "#":
                    recipients += getaddresses([addr])

        if not outer.has_key("Subject"):
            raise "Subject header is missing"
        if not outer.has_key("Date"):
            outer["Date"] = email.Utils.formatdate(None, True)

        for k, v in outer.items():
            print k, ":", unicode(v)
        #self.notice(str(outer.keys()))
        self.notice(_("Message size: %d bytes."), len(str(outer)))
        self.notice(_("Send this to %d recipients: %s"), len(recipients),
                    ", ".join([a[1] for a in recipients]))

        sender = parseaddr(unicode(sender))[1]

        # print "sender:", unicode(sender)

        # print outer.as_string(unixfrom=0)

        if not self.confirm("Okay?"):
            return

        self.connect()

        self.sendmsg(outer, sender, recipients)

        self.server.quit()

        self.notice(_("Sent to %d recipients."), self.count_ok)
        if self.count_nok != 0:
            self.notice(_("%d recipients refused."), self.count_nok)
示例#22
0
 def init(self,session,label=None,*args,**kw):
     self._label = label
     self._status = _("Working")
     BaseJob.init(self,session,*args,**kw)
示例#23
0
            target_mt = target_st.st_mtime
        except OSError,e:
            self.error("os.stat() failed: %s",e)
            return False

        doit = False
        if target_sz != src_sz:
            doit = True
        elif self.ignore_times:
            doit = False
        elif abs(target_mt - src_mt) > self.modify_window:
            doit = True
            if target_mt > src_mt:
                self.job.count_newer += 1
                self.warning(
                    _("Overwrite newer target %s") % target)

        
        if not doit:
            if self.job.simulate:
                self.job.count_same += 1
            else:
                self.job.done_same += 1
            self.debug(_("%s is up-to-date"), target)
            return
        
        if self.job.simulate:
            self.job.count_update_file += 1
            self.verbose("Must update %s", target)
            return
        
示例#24
0
 def summary(self):
     # may override
     self.session.notice(_("%d warnings"),self.count_warnings)
     self.session.notice(_("%d errors"), self.count_errors)
示例#25
0
    def run(self,safely=True,noaction=False):
        #self.session=task.session
        #self.task=task
        #self.maxval=0
        #for p in self.projects:
        #    self.notice(str(p))
            
##         if showProgress:
##             def f():
##                 for prj in self.projects:
##                     self.maxval += prj.countFiles(self)
##             Looper(f,_("Counting files...")).runfrom(self)
##             #sess.loop(f,_("Counting files..."))
##             self.notice(_("Found %d files."), self.maxval)
            
                
        if safely:
            self.simulate=True
            
##             def f(task):
##                 for p in self.projects:
##                     task.runtask(p)
##             self.loop(f,_("Analyzing..."),self.maxval)

            for p in self.projects:
                self.notice(_("Analyzing %s ..."),p)
                self.runtask(p)
                p.setMaxVal(p.curval)
            
            self.notice(self.getSummary())
            
            if not (self.count_delete_dir \
                 or self.count_delete_file \
                 or self.count_copy_file \
                 or self.count_copy_dir \
                 or self.count_update_file) :
                self.notice(_("Nothing to do"))
                return
            
                    
            if self.count_newer > 0:
                if not self.confirm(
                    _("%d target files are NEWER! Are you sure?") \
                    % self.count_newer, default=False):
                    return
        else:
            self.notice(self.getSummary())
            
        if noaction:
            return

        if not self.confirm(_("Start?")):
            return
        
        self.simulate=False
        
##         def f(task):
##             for p in self.projects:
##                 task.runtask(p)
##         self.loop(f,"Synchronizing",self.maxval)

        for p in self.projects:
            self.notice(_("Synchronizing %s ..."),p)
            self.runtask(p)
        
        self.notice(self.getSummary())
示例#26
0
 def requestAbort(self):
     if self.confirm(_("Are you sure you want to abort?"), default=False):
         raise UserAborted()
     #self._abortRequested=False
     self.toolkit.onTaskResume(self)
示例#27
0
            target_sz = target_st.st_size
            target_mt = target_st.st_mtime
        except OSError, e:
            self.error("os.stat() failed: %s", e)
            return False

        doit = False
        if target_sz != src_sz:
            doit = True
        elif self.ignore_times:
            doit = False
        elif abs(target_mt - src_mt) > self.modify_window:
            doit = True
            if target_mt > src_mt:
                self.job.count_newer += 1
                self.warning(_("Overwrite newer target %s") % target)

        if not doit:
            if self.job.simulate:
                self.job.count_same += 1
            else:
                self.job.done_same += 1
            self.debug(_("%s is up-to-date"), target)
            return

        if self.job.simulate:
            self.job.count_update_file += 1
            self.verbose("Must update %s", target)
            return

        if win32file: