"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/detectors/newitemcopy.py" (26 Aug 2019, 2641 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "newitemcopy.py": 1.6.1_vs_2.0.0.

    1 from roundup import hyperdb, roundupdb
    2 from roundup.mailer import Mailer
    3 
    4 
    5 def indentChangeNoteValue(text):
    6     # copied from roundupdb.IssueClass.indentChangeNoteValue()
    7     lines = text.rstrip('\n').split('\n')
    8     lines = [ '  '+line for line in lines ]
    9     return '\n'.join(lines)
   10 
   11 def generateCreateNote(db, cl, nodeid):
   12     # copied from roundupdb.IssueClass.generateCreateNote()
   13     cn = cl.classname
   14     props = cl.getprops(protected=0)
   15 
   16     # list the values
   17     m = []
   18     prop_items = sorted(props.items())
   19     for propname, prop in prop_items:
   20         value = cl.get(nodeid, propname, None)
   21         # skip boring entries
   22         if not value:
   23             continue
   24         if isinstance(prop, hyperdb.Link):
   25             link = db.classes[prop.classname]
   26             if value:
   27                 key = link.labelprop(default_to_id=1)
   28                 if key:
   29                     value = link.get(value, key)
   30             else:
   31                 value = ''
   32         elif isinstance(prop, hyperdb.Multilink):
   33             if value is None: value = []
   34             l = []
   35             link = db.classes[prop.classname]
   36             key = link.labelprop(default_to_id=1)
   37             if key:
   38                 value = [link.get(entry, key) for entry in value]
   39             value.sort()
   40             value = ', '.join(value)
   41         else:
   42             value = str(value)
   43             if '\n' in value:
   44                 value = '\n'+indentChangeNoteValue(value)
   45         m.append('%s: %s'%(propname, value))
   46     m.insert(0, '----------')
   47     m.insert(0, '')
   48     return '\n'.join(m)
   49 
   50 def newitemcopy(db, cl, nodeid, oldvalues):
   51     ''' Copy a message about new items to the dispatcher address.
   52     '''
   53     try:
   54         create_note = cl.generateCreateNote(nodeid)
   55     except AttributeError:
   56         create_note = generateCreateNote(db, cl, nodeid)
   57 
   58     try:
   59         dispatcher_email = getattr(db.config, 'DISPATCHER_EMAIL')
   60     except AttributeError:
   61         return
   62 
   63     try:
   64         msgids = cl.get(nodeid, 'messages')
   65     except KeyError:
   66         msgids = None
   67 
   68     if msgids:
   69         # send a copy to the dispatcher
   70         for msgid in msgids:
   71             try:
   72                 cl.send_message(nodeid, msgid, create_note, [dispatcher_email])
   73             except roundupdb.MessageSendError as message:
   74                 raise roundupdb.DetectorError(message)
   75     else:
   76         mailer = Mailer(db.config)
   77         subject = 'New %s%s' % (cl.classname, nodeid)
   78         mailer.standard_message([dispatcher_email], subject, create_note)
   79 
   80 def init(db):
   81     for classname in db.getclasses():
   82         cl = db.getclass(classname)
   83         cl.react('create', newitemcopy)