コード例 #1
0
ファイル: make.py プロジェクト: cameron-simpson/css
 def report(self, fp=None):
     ''' Report the make queue status.
 '''
     D("REPORT...")
     if fp is None:
         fp = sys.stderr
     fp.write(str(self))
     fp.write(': ')
     fp.write(repr(self._makeQ))
     fp.write('\n')
     D("REPORTED")
コード例 #2
0
 def _testSingleRule(self,
                     rule_lines,
                     target_types,
                     labelstr,
                     conditions=None,
                     flags=None):
     if isinstance(rule_lines, str):
         rule_lines = (rule_lines, )
     if flags is None:
         flags = NS(alert=False, halt=False)
     R, = list(parserules(rule_lines))
     D("R = %s", R)
     self.assertEqual(len(R.targets), len(target_types))
     for T, Ttype in zip(R.targets, target_types):
         self.assertIsInstance(T, Ttype)
     self.assertEqual(R.label, labelstr)
     self.assertEqual(R.flags.alert, flags.alert)
     self.assertEqual(R.flags.halt, flags.halt)
     if conditions is not None:
         self.assertEqual(len(R.conditions), len(conditions))
         for i in range(len(conditions)):
             C = conditions[i]
             RC = R.conditions[i]
             D("C = %s", C)
             for attr in dir(C):
                 if attr[0].isalpha():
                     D("test attr %s: %s VS %s", attr, getattr(C, attr),
                       getattr(RC, attr))
                     if attr == 'flags':
                         Cflags = C.flags
                         RCflags = RC.flags
                         for flag_name in dir(RC.flags):
                             if flag_name == 'D':
                                 continue
                             if flag_name[0].isalpha():
                                 if getattr(RCflags, flag_name):
                                     self.assertTrue(
                                         flag_name in Cflags,
                                         "\"%s\" in Rule but not expected" %
                                         (flag_name, ))
                                 else:
                                     self.assertTrue(
                                         flag_name not in Cflags,
                                         "\"%s\" expected, but not in Rule"
                                         % (flag_name, ))
                     else:
                         av1 = getattr(C, attr)
                         av2 = getattr(RC, attr)
                         if not callable(av1) and not callable(av2):
                             self.assertEqual(getattr(C, attr),
                                              getattr(RC, attr))
コード例 #3
0
ファイル: later.py プロジェクト: cameron-simpson/css
 def state(self, new_state, *a):
   ''' Update the state of this Later.
   '''
   if a:
     new_state = new_state % a
   D("STATE %r [%s]", new_state, self)
   self._state = new_state
コード例 #4
0
 def address_groups(self):
   ''' Compute the address_group sets, a mapping of GROUP names to a
       set of A.name.lower().
       Return the mapping.
   '''
   try:
     agroups = {'all': set()}
     allgroup = agroups['all']
     for A in self.ADDRESSes:
       coreaddr = A.name
       if coreaddr != coreaddr.lower():
         warning(
             'ADDRESS %r does not have a lowercase .name attribute: %s', A,
             A.name
         )
       for group_name in A.GROUPs:
         agroup = agroups.setdefault(group_name, set())
         agroup.add(coreaddr)
         allgroup.add(coreaddr)
   except AttributeError as e:
     D("address_groups(): e = %r", e)
     raise ValueError("disaster")
   return agroups
コード例 #5
0
def updateNodeDB(maildb, people):
  ''' Update the specified `maildb` with the addressbook `people`.
  '''
  for person in people:
    cite = '%s %s/%s' % ( person.get('First',''), person.get('Last',''), person.get('Organization','') )
    with Pfx('updateNodeDB: %s', cite):
      uid = person['UID']
      C = contactByOSXUID(maildb, uid)
      if C:
        info("EXISTING CONTACT: OSX_AB_UID = %s: %s", uid, cite)
      else:
        warning("NEW CONTACT: OSX_AB_UID = %s", uid)
        C = maildb.seqNode('CONTACT')
        C.OSX_AB_UID = str(uid)

      lastUpdate = C.get0('OSX_AB_LAST_UPDATE', 0)
      abMTime = mtime(person, 0)
      D("USER %s %s: abMTime=%s, lastUpdate=%s", uid, cite, abMTime, lastUpdate)
      if abMTime > lastUpdate:
        print("UPDATE USER %s" % (cite,))
        ## C.OSX_AB_LAST_UPDATE = abMTime
        ok = True
        for k, v in person.items():
          if k in ('UID', 'Creation', 'Modification',
                   'com.apple.carddavvcf',
                   'com.apple.vcardhash',
                   'com.apple.uuid',
                   'com.apple.etag',
                   'com.apple.collectionpath',
                   'com.apple.synced',
                  ):
            info("ignore %s: %r", k, v)
          elif k == 'ABPersonFlags':
            if v & AB_FLAGS_ORGANIZATION:
              C.FLAGs.add('ORGANIZATION')
              v &= ~AB_FLAGS_ORGANIZATION
            if v != 0:
              warning("unhandled ABPersonFlags: 0x%x", v)
              ok = False
          elif k == 'First':
            C.FIRST_NAME = v
          elif k == 'Last':
            C.LAST_NAME = v
          elif k == 'Organization':
            C.ORGANIZATION = v
          # TODO: split job title into one per org
          elif k == 'JobTitle':
            C.JOB_TITLE = v
          elif k == 'Email':
            C.EMAIL_ADDRESSes.update(v)
          elif k == 'Phone':
            C.TELEPHONEs.update(v)
          elif k == 'Address':
            for addr in v:
              if addr not in C.ADDRESSes:
                N = maildb.seqNode('ADDRESS')
                N.COUNTRY = str(addr.get('Country', ''))
                N.STATE = str(addr.get('State', ''))
                N.STREETs = [ line for line in map(lambda it : it.strip(), addr.get('Street', '').split('\n')) if len(line) ]
                N.POSTAL_CODE = str(addr.get('ZIP', ''))
                C.ADDRESSes.append(N)
          elif k == 'Note':
            v = v.strip()
            if v:
              C.NOTEs.add(v)
          elif k == 'URLs':
            C.URLs.update( url for url in map(lambda U: U.strip(), v) )
          else:
            warning("unhandled AB key: %s: %r", k, v)
            pprint.pprint(person)
            ok = False
        if ok:
          info("SKIP OSX_AB_LAST_UPDATE update")
          ##C.OSX_AB_LAST_UPDATE = abMTime
      else:
        info("SKIP USER %s", cite)
コード例 #6
0
ファイル: debug.py プロジェクト: cameron-simpson/css
 def subfunc(*a, **kw):
     frame = caller()
     D("CALL %s()<%s:%d> FROM %s()<%s:%d>", func.__name__,
       func.__code__.co_filename, func.__code__.co_firstlineno,
       frame.funcname, frame.filename, frame.lineno)
     return func(*a, **kw)
コード例 #7
0
ファイル: debug.py プロジェクト: cameron-simpson/css
def dump_debug_threads():
    D("dump_debug_threads:")
    for T in _debug_threads:
        D("dump_debug_threads: thread %r: %r", T.name, T.debug_label)
    D("dump_debug_threads done")
コード例 #8
0
ファイル: debug.py プロジェクト: cameron-simpson/css
 def __init__(self, dkw):
     D("dkw = %r", dkw)
     DebugWrapper.__init__(self, **dkw)
     self.debug('__init__')
     self.lock = threading.RLock()
     self.stack = None
コード例 #9
0
 def tearDown(self):
     if os.path.exists(self.lockpath):
         D("remove lockfile %s", self.lockpath)
         os.remove(self.lockpath)