Beispiel #1
0
 def try_insert_address(self, m, person):
     street = ' '.join(x for x in (m.street, m.housenumber) if x)
     if street or m.town or m.zip:
         country = 'Austria'.decode('latin1')
         if not m.town:
             pyk.fprint \
                 ( 'INFO: no city (setting to "Wien"): %s/%s'
                 % (m.id, person.pid)
                 )
             m['town'] = 'Wien'
         if not m.zip:
             if m.id == 653:
                 m['zip'] = 'USA'
             elif m.id == 787:
                 m['zip'] = '2351'
             elif m.id == 836:
                 m['zip'] = '1160'
             else:
                 pyk.fprint("INFO: no zip: %s/%s" % (m.id, person.pid))
         elif m.zip.startswith('I-'):
             m['zip'] = m.zip[2:]
             country = 'Italy'.decode('latin1')
         address = self.pap.Address.instance_or_new \
             ( street     = street
             , zip        = m.zip
             , city       = m.town
             , country    = country
             )
         self.pap.Subject_has_Address(person, address)
Beispiel #2
0
def _main (cmd) :
    ATAX.Command.load_config (cmd)
    fb = Fahrtenbuch.from_file (cmd.user, cmd.fahrtenbuch)
    if not cmd.km_geld :
        pyk.fprint (fb.tex ())
    else :
        pyk.fprint (fb.km_geld ())
Beispiel #3
0
 def try_insert_phone (self, person, m, x, c) :
     if x :
         p = None
         if x in self.phone_bogus :
             return
         try :
             p = Phone (x, m.town, c)
         except ValueError, err :
             if str (err).startswith ('WARN') :
                 pyk.fprint (err)
                 return
         if not p :
             return
         t = self.pap.Phone.instance (* p)
         k = str (p)
         if t :
             eid = self.phone_ids [k]
             prs = self.person_by_id [eid]
             if  (  prs.pid == person.pid
                 or self.pap.Subject_has_Phone.instance (person, t)
                 ) :
                 return # don't insert twice
             pyk.fprint \
                 ( "WARN: %s/%s %s/%s: Duplicate phone: %s"
                 % (eid, prs.pid, m.id, person.pid, x)
                 )
         else :
             t = self.pap.Phone (* p)
             self.phone_ids [k] = m.id
         self.pap.Subject_has_Phone (person, t)
Beispiel #4
0
 def try_insert_email(self, person, m, attr="email", second=False):
     mail = getattr(m, attr)
     email = self.pap.Email.instance(address=mail)
     if email:
         if mail.lower() in (e.address for e in person.emails):
             return
         eid = self.email_ids[mail.lower()]
         prs = self.person_by_id[eid]
         pyk.fprint("WARN: %s/%s %s/%s: Duplicate email: %s" % (eid, prs.pid, m.id, person.pid, mail))
     else:
         desc = None
         if second:
             desc = "von 2. Account"
             pyk.fprint("INFO: Second email for %s/%s: %s" % (m.id, person.pid, mail))
         self.email_ids[mail.lower()] = m.id
         email = self.pap.Email(address=mail, desc=desc)
         self.pap.Subject_has_Email(person, email)
         if m.id not in self.company_actor and m.id not in self.association_actor:
             # Some accounts are in fixtures
             auth = self.scope.Auth.Account.instance(mail)
             if not auth:
                 auth = self.scope.Auth.Account.create_new_account_x(
                     mail, enabled=True, suspended=True, password=uuid.uuid4().hex
                 )
             self.pap.Person_has_Account(person, auth)
Beispiel #5
0
 def try_insert_phone(self, person, m, x, c):
     if x:
         p = None
         if x in self.phone_bogus:
             return
         try:
             p = Phone(x, m.town, c)
         except ValueError, err:
             if str(err).startswith('WARN'):
                 pyk.fprint(err)
                 return
         if not p:
             return
         t = self.pap.Phone.instance(*p)
         k = str(p)
         if t:
             eid = self.phone_ids[k]
             prs = self.person_by_id[eid]
             if (prs.pid == person.pid
                     or self.pap.Subject_has_Phone.instance(person, t)):
                 return  # don't insert twice
             pyk.fprint \
                 ( "WARN: %s/%s %s/%s: Duplicate phone: %s"
                 % (eid, prs.pid, m.id, person.pid, x)
                 )
         else:
             t = self.pap.Phone(*p)
             self.phone_ids[k] = m.id
         self.pap.Subject_has_Phone(person, t)
Beispiel #6
0
def _main(cmd):
    ATAX.Command.load_config(cmd)
    fb = Fahrtenbuch.from_file(cmd.user, cmd.fahrtenbuch)
    if not cmd.km_geld:
        pyk.fprint(fb.tex())
    else:
        pyk.fprint(fb.km_geld())
Beispiel #7
0
 def try_insert_address (self, m, person) :
     street  = ' '.join (x for x in (m.street, m.housenumber) if x)
     if street or m.town or m.zip :
         country = 'Austria'.decode ('latin1')
         if not m.town :
             pyk.fprint \
                 ( 'INFO: no city (setting to "Wien"): %s/%s'
                 % (m.id, person.pid)
                 )
             m ['town'] = 'Wien'
         if not m.zip :
             if m.id == 653 :
                 m ['zip'] = 'USA'
             elif m.id == 787 :
                 m ['zip'] = '2351'
             elif m.id == 836 :
                 m ['zip'] = '1160'
             else :
                 pyk.fprint ("INFO: no zip: %s/%s" % (m.id, person.pid))
         elif m.zip.startswith ('I-') :
             m ['zip'] = m.zip [2:]
             country = 'Italy'.decode ('latin1')
         address = self.pap.Address.instance_or_new \
             ( street     = street
             , zip        = m.zip
             , city       = m.town
             , country    = country
             )
         self.pap.Subject_has_Address (person, address)
Beispiel #8
0
 def add_redeemer_ip(self, ip):
     """ Add redeemer ip address. """
     assert not ip.id_nodes
     if ip.id_members or ip.id_members != 1:
         pyk.fprint("WARN: IP %s %s has member ID %s" % (ip.ip, ip.id, ip.id_members))
     assert not self.merged_devs
     assert ip.ip not in self.interfaces
     self.interfaces[ip.ip] = Consolidated_Interface(self.convert, self, ip, self.if_idx)
     self.if_idx += 1
Beispiel #9
0
def _main (cmd) :
    source = cmd.source_currency
    total  = source (0)
    for a in cmd.argv :
        c = source (a)
        pyk.fprint ("%s %s = %s" % (a, source.sloppy_name, c))
        total += c
    if total != 0 and len (cmd.argv) > 1 :
        pyk.fprint ("Total : %s" % total)
Beispiel #10
0
 def reserve_net(self, nets, typ):
     for net, comment in sorted(nets.iteritems(), key=ip_mask_key):
         if self.verbose:
             pyk.fprint(net, comment)
         r = typ.query(Q.net_address.CONTAINS(net), sort_key=TFL.Sorted_By("-net_address.mask_len")).first()
         reserver = r.reserve if r else typ
         network = reserver(net, owner=self.ff_subject)
         if isinstance(comment, type("")):
             network.set_raw(desc=comment[:80])
Beispiel #11
0
 def merge(self, other):
     """ Merge other interface into this one """
     assert other.device == self.device
     assert not other.merged
     if self.debug:
         pyk.fprint("Merge: %s\n    -> %s" % (other, self))
         pyk.fprint("Merge: dev: %s" % self.device)
     self.ips.update(other.ips)
     del other.device.interfaces[other.ip]
     self.merged_ifs.append(other)
     other.merged = self
Beispiel #12
0
 def reserve_net(self, nets, typ):
     for net, comment in sorted(nets.iteritems(), key=ip_mask_key):
         if self.verbose:
             pyk.fprint(net, comment)
         r = typ.query \
             ( Q.net_address.CONTAINS (net)
             , sort_key = TFL.Sorted_By ("-net_address.mask_len")
             ).first ()
         reserver = r.reserve if r else typ
         network = reserver(net, owner=self.ff_subject)
         if isinstance(comment, type('')):
             network.set_raw(desc=comment[:80])
Beispiel #13
0
 def from_file (cls, user, file_name) :
     Entry  = cls.Entry
     result = cls (user)
     add    = result.add
     last   = None
     with open (file_name, "rb") as file :
         for l in result._read_lines (file) :
             try :
                 last = Entry.from_line (l, last)
             except ValueError as exc :
                 pyk.fprint (exc)
             else :
                 add (last)
     return result
Beispiel #14
0
 def from_file(cls, user, file_name):
     Entry = cls.Entry
     result = cls(user)
     add = result.add
     last = None
     with open(file_name, "rb") as file:
         for l in result._read_lines(file):
             try:
                 last = Entry.from_line(l, last)
             except ValueError as exc:
                 pyk.fprint(exc)
             else:
                 add(last)
     return result
Beispiel #15
0
def _main(cmd):
    """For each argument, write sanitized_filename to stdout. If `-rename` is
       specified, the files are renamed to the sanitized_filenames instead.
    """
    from _TFL import sos
    from _TFL.pyk import pyk

    for f in cmd.argv:
        sf = sanitized_filename(pyk.decoded(f))
        if cmd.rename:
            sos.rename(f, sf)
            if cmd.verbose:
                pyk.fprint("Renamed", f, "to", sf)
        else:
            pyk.fprint(sf, end=" ")
def _main (cmd) :
    import fileinput
    lines = fileinput.input (cmd.argv)
    if cmd.output :
        sys.stdout = open (cmd.output, "a")
    for l in lines :
        if isinstance (l, str) :
            l = TFL.I18N.decode (l)
        ll = date_time_localizer (l, cmd.format)
        try :
            pyk.fprint (ll, end = "")
        except IOError :
            import sys
            sys.exit (0)
    pyk.fprint ()
Beispiel #17
0
 def _run_setup (cls, directory, plugin_name) :
     fname = os.path.join (directory, "_%s.t3p" % plugin_name)
     try :
         zim = zipimport.zipimporter (fname)
     except ImportError :
         if __debug__ :
             pyk.fprint ("Could not import from %s" % fname)
         return
     sname     = "_setup"
     setup_mod = zim.find_module (sname)
     if not setup_mod :
         if __debug__ :
             pyk.fprint ("Could not find '%s' in %s" % (sname, fname))
         return
     zim.load_module (sname)
Beispiel #18
0
def _main(cmd):
    """For each argument, write sanitized_filename to stdout. If `-rename` is
       specified, the files are renamed to the sanitized_filenames instead.
    """
    from _TFL import sos
    from _TFL.pyk import pyk
    for f_b in cmd.argv:
        f = pyk.decoded(f_b)
        sf = sanitized_filename(f)
        sf_b = pyk.encoded(sf)
        if cmd.rename:
            if f_b != sf_b and sos.path.exists(f_b):
                sos.rename(f_b, sf_b)
                if cmd.verbose:
                    pyk.fprint("Renamed", f, "to", sf)
        else:
            pyk.fprint(sf, end=cmd.separator)
Beispiel #19
0
def _main (cmd) :
    """For each argument, write sanitized_filename to stdout. If `-rename` is
       specified, the files are renamed to the sanitized_filenames instead.
    """
    from _TFL     import sos
    from _TFL.pyk import pyk
    for f_b in cmd.argv :
        f    = pyk.decoded (f_b)
        sf   = sanitized_filename (f)
        sf_b = pyk.encoded (sf)
        if cmd.rename :
            if f_b != sf_b and sos.path.exists (f_b) :
                sos.rename (f_b, sf_b)
                if cmd.verbose :
                    pyk.fprint ("Renamed", f, "to", sf)
        else :
            pyk.fprint (sf, end = cmd.separator)
Beispiel #20
0
 def _handle_script (self, cao) :
     scope = self._handle_load (cao) if cao.load else None
     globs = self._handle_script_globals (cao = cao, scope = scope)
     for script_path in cao.argv :
         local  = {}
         try :
             with open (script_path, "rb") as f :
                 exec (f.read (), globs, local)
         except Exception as exc :
             head = _T ("Script %s triggered exception" % (script_path, ))
             tail = "    \n".join (pyk.text_type (exc).split ("\n"))
             pyk.fprint (head)
             pyk.fprint ("   ", tail)
             raise SystemExit (1)
     if cao.commit :
         scope.commit      ()
         scope.ems.compact ()
         scope.destroy     ()
Beispiel #21
0
 def _handle_script(self, cao):
     scope = self._handle_load(cao) if cao.load else None
     globs = self._handle_script_globals(cao=cao, scope=scope)
     for script_path in cao.argv:
         local = {}
         try:
             with open(script_path, "rb") as f:
                 exec(f.read(), globs, local)
         except Exception as exc:
             head = _T("Script %s triggered exception" % (script_path, ))
             tail = "    \n".join(pyk.text_type(exc).split("\n"))
             pyk.fprint(head)
             pyk.fprint("   ", tail)
             raise SystemExit(1)
     if cao.commit:
         scope.commit()
         scope.ems.compact()
         scope.destroy()
Beispiel #22
0
 def merge(self, other):
     """ Merge other device into this one """
     self.redeemer_devs.update(other.redeemer_devs)
     self.interfaces.update(other.interfaces)
     if self.debug:
         pyk.fprint("Merge: %s\n    -> %s" % (other, self))
     # assert not other.merged
     if other.merged:
         msg = "Merge: already merged to %s" % other.merged
         pyk.fprint(msg)
         raise ValueError(msg)
     for ifc in other.interfaces.itervalues():
         ifc.device = self
     other.merged = self
     other.set_done()
     self.merged_devs.append(other)
     assert self.devid in self.redeemer_devs
     assert other.devid in self.redeemer_devs
Beispiel #23
0
 def create(self):
     """ Create device in database """
     assert self.net_device is None
     assert not self.merged
     ffm = self.convert.ffm
     if self.debug:
         pyk.fprint('dev:', self.id, self.name)
     if self.if_idx > 1:
         pyk.fprint \
             ( "WARN: dev %s.%s has %d ips in redeemer" \
             % (self.node.name, self.name, self.if_idx)
             )
     for d in self.merged_devs:
         if d.if_idx > 1:
             pyk.fprint \
                 ( "WARN: dev %s.%s has %d ips in redeemer" \
                 % (d.node.name, d.name, self.if_idx)
                 )
     # FIXME: We want correct info from nodes directly
     # looks like most firmware can give us this info
     devtype = ffm.Net_Device_Type.instance(name='Generic')
     comments = dict \
         ( hardware = 'Hardware'
         , antenna  = 'Antenne'
         , comment  = 'Kommentar'
         )
     d = self.redeemer_devs[self.devid]
     desc = '\n'.join \
         (': '.join ((v, d [k])) for k, v in comments.iteritems () if d [k])
     dev = self.net_device = ffm.Net_Device \
         ( left = devtype
         , node = self.ffm_node
         , name = self.shortest_name
         , desc = desc
         , raw  = True
         )
     self.convert.set_last_change(dev, self.changed, self.created)
     # no member info in DB:
     assert not self.id_members
     for iface in self.interfaces.itervalues():
         iface.create()
     self.convert.scope.commit()
     return dev
Beispiel #24
0
 def create (self) :
     """ Create device in database """
     assert self.net_device is None
     assert not self.merged
     ffm = self.convert.ffm
     if self.debug :
         pyk.fprint ('dev:', self.id, self.name)
     if self.if_idx > 1 :
         pyk.fprint \
             ( "WARN: dev %s.%s has %d ips in redeemer" \
             % (self.node.name, self.name, self.if_idx)
             )
     for d in self.merged_devs :
         if d.if_idx > 1 :
             pyk.fprint \
                 ( "WARN: dev %s.%s has %d ips in redeemer" \
                 % (d.node.name, d.name, self.if_idx)
                 )
     # FIXME: We want correct info from nodes directly
     # looks like most firmware can give us this info
     devtype = ffm.Net_Device_Type.instance (name = 'Generic')
     comments = dict \
         ( hardware = 'Hardware'
         , antenna  = 'Antenne'
         , comment  = 'Kommentar'
         )
     d    = self.redeemer_devs [self.devid]
     desc = '\n'.join \
         (': '.join ((v, d [k])) for k, v in comments.iteritems () if d [k])
     dev = self.net_device = ffm.Net_Device \
         ( left = devtype
         , node = self.ffm_node
         , name = self.shortest_name
         , desc = desc
         , raw  = True
         )
     self.convert.set_last_change (dev, self.changed, self.created)
     # no member info in DB:
     assert not self.id_members
     for iface in self.interfaces.itervalues () :
         iface.create ()
     self.convert.scope.commit ()
     return dev
Beispiel #25
0
 def _write_entry (self, e) :
     ifb_indicator = ""
     if e.ifb :
         ifb_indicator = e.ifb.abbr
     pyk.fprint \
         ( self.entry1_format
         % ( e.desc
           , ifb_indicator
           , e.birth_time.formatted ("%d.%m.%y")
           , e.birth_value
           , e.head_value
           , e.base_rate
           , e.current_depreciation
           , e.tail_value
           )
         )
     if e.alive :
         if e.ifb and e.ifb.is_new :
             pyk.fprint \
                 ( self.newifb_format
                 % ( e.supplier, "", "", "", e.ifb.abbr, e.ifb.value, "")
                 )
         elif e.ifb :
             pyk.fprint ("  %-36s%10.2f" % (e.supplier, e.ifb.value))
         else :
             pyk.fprint \
                 ( self.alive_format
                 % (e.supplier, "", "", "", ("", "ewig") ["=" in e.flags])
                 )
     else :
         pyk.fprint \
             ( self.dying_format
             % ( e.supplier
               , "Abgang"
               , e.death_time.formatted ("%d.%m.%y")
               , ifb_indicator
               , ("", e.ifb.value.as_string_s ()) [bool (e.ifb)]
               , ("", "ewig") ["=" in e.flags]
               , e.out_value
               , ""
               )
             )
Beispiel #26
0
 def try_insert_address(self, m, person):
     street = " ".join(x for x in (m.street, m.housenumber) if x)
     if street or m.town or m.zip:
         country = "Austria".decode("utf-8")
         if not m.town:
             pyk.fprint('INFO: no city (setting to "Wien"): %s/%s' % (m.id, person.pid))
             m["town"] = "Wien"
         if not m.zip:
             if m.id == 653:
                 m["zip"] = "USA"
             elif m.id == 787:
                 m["zip"] = "2351"
             elif m.id == 836:
                 m["zip"] = "1160"
             else:
                 pyk.fprint("INFO: no zip: %s/%s" % (m.id, person.pid))
         elif m.zip.startswith("I-"):
             m["zip"] = m.zip[2:]
             country = "Italy".decode("utf-8")
         if not street and not m.zip and m.town == "Wien":
             return
         if not street:
             pyk.fprint("INFO: no street: %s/%s" % (m.id, person.pid))
             return
         address = self.pap.Address.instance_or_new(street=street, zip=m.zip, city=m.town, country=country)
         self.pap.Subject_has_Address(person, address)
Beispiel #27
0
def time_block (fmt = "Execution time: %s", out = None, cb = None) :
    """Context manager measuring the execution time for a block.

       After finishing the block, `cb` will be called with the arguments
       `start`, `finish`, and `delta`, if specified.

       Otherwise, `time_block` will use `fmt` to write the execution time to
       sys.stdout.
    """
    start  = _timer ()
    yield
    finish = _timer ()
    delta  = finish - start
    if cb is not None :
        cb (start, finish, delta)
    else :
        from _TFL.pyk import pyk
        try :
            msg = fmt % (delta, )
        except (TypeError, ValueError) as exc :
            msg = "%s: %s" % (fmt, delta)
        pyk.fprint (msg, file = out)
Beispiel #28
0
def time_block(fmt="Execution time: %s", out=None, cb=None):
    """Context manager measuring the execution time for a block.

       After finishing the block, `cb` will be called with the arguments
       `start`, `finish`, and `delta`, if specified.

       Otherwise, `time_block` will use `fmt` to write the execution time to
       sys.stdout.
    """
    start = _timer()
    yield
    finish = _timer()
    delta = finish - start
    if cb is not None:
        cb(start, finish, delta)
    else:
        from _TFL.pyk import pyk
        try:
            msg = fmt % (delta, )
        except (TypeError, ValueError) as exc:
            msg = "%s: %s" % (fmt, delta)
        pyk.fprint(msg, file=out)
Beispiel #29
0
 def debug_output (self) :
     for k in sorted (self.olsr_nodes.iterkeys ()) :
         pyk.fprint (k)
     for node in self.contents ['nodes'] :
         nn = node.name.encode ('latin1')
         pyk.fprint ("Node: %s (%s)" % (nn, node.id))
         for d in self.dev_by_node.get (node.id, []) :
             pyk.fprint ("    Device: %s" % d.name)
Beispiel #30
0
 def debug_output(self):
     for k in sorted(self.olsr_nodes.iterkeys()):
         pyk.fprint(k)
     for node in self.contents['nodes']:
         nn = node.name.encode('latin1')
         pyk.fprint("Node: %s (%s)" % (nn, node.id))
         for d in self.dev_by_node.get(node.id, []):
             pyk.fprint("    Device: %s" % d.name)
Beispiel #31
0
 def try_insert_im(self, person, m):
     if m.instant_messenger_nick.endswith("@aon.at"):
         self.try_insert_email(person, m, attr="instant_messenger_nick")
         return
     if m.instant_messenger_nick.startswith("alt/falsch"):
         return
     if m.instant_messenger_nick.startswith("housing"):
         return
     if self.im_hash.match(m.instant_messenger_nick):
         pyk.fprint("WARN: Got hash in nick: %s" % m.instant_messenger_nick)
         return
     if m.instant_messenger_nick.startswith("Wohnadresse:"):
         adr = m.instant_messenger_nick.split(":", 1)[1].strip()
         # delimiter is a literal backslash followed by n
         street, r = adr.split(r"\n")
         plz, ort = r.split()
         address = self.pap.Address.instance_or_new(
             street=street, zip=plz, city=ort, country="Austria".decode("utf-8")
         )
         self.pap.Subject_has_Address(person, address)
         return
     pyk.fprint("INFO: Instant messenger nickname: %s" % m.instant_messenger_nick)
     im = self.pap.IM_Handle(address=m.instant_messenger_nick)
     self.pap.Subject_has_IM_Handle(person, im)
Beispiel #32
0
def _main (cmd) :
    PMA.default_encoding = encoding = \
        "iso8859-1" if cmd.Print else pyk.user_config.output_encoding
    for msg in messages_from_args (cmd.argv, cmd.msg_base_dirs) :
        txt = formatted (msg, encoding = encoding)
        if cmd.Print :
            from plumbum  import local as pbl
            from _TFL.FCM import open_tempfile
            subject = msg.scope.subject
            pbl.env ["LC_ALL"] = "en_US.%s" % encoding.replace ("-", "")
            with open_tempfile () as (file, temp_name) :
                file.write (txt)
                file.close ()
                a2ps = pbl ["a2ps"] \
                    [ "-s", "-8", "-nL", "-nu", "-nS"
                    , pyk.encoded ("-H%s" % (subject, ), encoding)
                    , "-P%s" % (cmd.printer_name, )
                    , temp_name
                    ]
                if cmd.verbose :
                    print (a2ps)
                a2ps ()
        else :
            pyk.fprint (pyk.decoded (txt, encoding))
Beispiel #33
0
 def _send_registration_email \
         ( self, resource, request, response, scope, fv, result, message
         , subject_tail = ""
         ):
     try :
         email = self.email_from
         self.send_email \
             ( self.register_email_template
             , email_from    = email
             , email_to      = email
             , email_subject = _T ("%s: regatta registration %s")
                   % (self.obj.ui_display, subject_tail)
             , message       = message
             , NAV           = self.top
             , page          = self
             , request       = request
             )
     except Exception as exc :
         pyk.fprint \
             ( "Sending regatta registration email to %r failed "
               "with exception %s"
             % (email, exc)
             )
         pyk.fprint (message)
Beispiel #34
0
 def _send_registration_email \
         ( self, resource, request, response, scope, fv, result, message
         , subject_tail = ""
         ):
     try :
         email = self.email_from
         self.send_email \
             ( self.register_email_template
             , email_from    = email
             , email_to      = email
             , email_subject = _T ("%s: regatta registration %s")
                   % (self.obj.ui_display, subject_tail)
             , message       = message
             , NAV           = self.top
             , page          = self
             , request       = request
             )
     except Exception as exc :
         pyk.fprint \
             ( "Sending regatta registration email to %r failed "
               "with exception %s"
             % (email, exc)
             )
         pyk.fprint (message)
Beispiel #35
0
 def create(self):
     assert not self.merged
     dev = self.device.net_device
     if self.debug:
         pyk.fprint("device: %s ip: %s" % (self.device, self.ip))
     ffm = self.convert.ffm
     desc = []
     if self.names:
         desc.append("Spider Interfaces: %s" % ", ".join(self.names))
     if self.spider_ip:
         desc.append("Spider IP: %s" % self.spider_ip)
     desc = "\n".join(desc) or None
     if self.is_wlan:
         iface = self.net_interface = ffm.Wireless_Interface(left=dev, name=self.ifname, desc=desc, raw=True)
         if self.wlan_info:
             std = None
             if self.wlan_info.standard is not None:
                 std = ffm.Wireless_Standard.instance(name=self.wlan_info.standard, raw=True)
             mode = None
             if self.wlan_info.mode:
                 mode = self.wlan_info.mode.lower()
                 mode = self.wl_modes[mode]
             bsid = self.wlan_info.bssid
             ssid = self.wlan_info.ssid
             if bsid is not None and len(bsid.split(":")) != 6:
                 pyk.fprint("INFO: Ignoring bssid: %s" % bsid)
                 bsid = None
             if ssid is not None:
                 ssid = ssid.replace(r"\x09", "\x09")
             iface.set_raw(mode=mode, essid=ssid, bssid=bsid, standard=std)
             if self.wlan_info.channel is not None:
                 chan = ffm.Wireless_Channel.instance(std, self.wlan_info.channel, raw=True)
                 ffm.Wireless_Interface_uses_Wireless_Channel(iface, chan)
     else:
         iface = self.net_interface = ffm.Wired_Interface(left=dev, name=self.ifname, desc=desc, raw=True)
     manager = dev.node.manager
     scope = self.convert.scope
     for ip in self.ips.itervalues():
         if self.verbose:
             pyk.fprint(
                 "Adding IP %s to iface: %s/%s (of dev %s)" % (ip.ip, self.name, self.idxdev.name, self.device.name)
             )
         assert not ip.done
         ip.set_done()
         net = IP4_Address(ip.ip, ip.cidr)
         network = ffm.IP4_Network.instance(net)
         netadr = network.reserve(ip.ip, manager)
         ffm.Net_Interface_in_IP4_Network(iface, netadr, mask_len=32, name=self.ipname)
         if len(scope.uncommitted_changes) > 10:
             scope.commit()
Beispiel #36
0
 def check_spider_dev(self, sdev, in4, ips, nodeid):
     i4 = in4.ip
     nodename = self.ffm_node_by_id[nodeid].name
     if not routable(i4):
         return
     ip4 = IP4_Address(i4)
     if i4 not in ips:
         pyk.fprint("WARN: IP %s of spidered device %s not in mid dev for node %s" % (i4, sdev.mainip, nodename))
         if ip4 not in self.ip_by_ip:
             pyk.fprint("WARN: IP %s of spidered device %s not in ips" % (i4, sdev.mainip))
         else:
             d = self.ip_by_ip[ip4].id_devices
             if d:
                 dev = self.dev_by_id[d]
                 nid = dev.id_nodes
                 node = self.ffm_node_by_id[dev.id_nodes]
                 pyk.fprint(
                     "WARN: IP %s of spidered device %s"
                     " belongs to dev %s node %s" % (i4, sdev.mainip, dev.name, node.name)
                 )
             else:
                 pyk.fprint("WARN: IP %s of spidered device %s has no device" % (i4, sdev.mainip))
Beispiel #37
0
 def _Reload (self, * modules) :
     """Reload all the `modules` of the `Package_Namespace` specified
        (default: all modules of the `Package_Namespace` currently imported).
     """
     old_reload  = self.__reload
     if not modules :
         modules = self.MODULES
     try :
         self.__reload = 1
         pyk.fprint ("Reloading", self.__bname, end = " ")
         for m in modules :
             pyk.fprint (m.__name__, end = " ")
             m         = reload (m)
             m.__PNS__ = self
         pyk.fprint ("finished")
     finally :
         self.__reload = old_reload
     import linecache
     linecache.clearcache ()
Beispiel #38
0
 def write (self) :
     pyk.fprint \
         ( self.header_format
         % ( "", "", "Anschaff/", "Buchwert", " Afa ", "Afa", "Buchwert")
         )
     pyk.fprint \
         ( self.header_format
         % ( "Text", "Datum", "Teil-Wert", "1.1.", "  %  "
           , "IFB/Abgang", "31.12."
           )
         )
     pyk.fprint ("\n%s\n" % ("=" * 116, ))
     for e in self.entries :
         if e.active :
             self._write_entry (e)
     pyk.fprint ("\n%s\n" % ("=" * 116, ))
     pyk.fprint \
         ( self.footer_format
         % ( "Summe", ""
           , self.total_birth_value
           , self.total_head_value
           , "Afa"
           , self.total_depreciation
           , self.total_tail_value
           )
         )
     if len (self.total_per_cat) > 1 :
         for k, v in sorted (pyk.iteritems (self.total_per_cat)) :
             pyk.fprint ((self.out_format % ("", "", "", "", k, v)))
     pyk.fprint \
         (self.new_format % ("Neuzugänge", "", "", self.total_new_value))
     pyk.fprint \
         ( self.out_format
         % ("Abgänge", "", "", "", "", self.total_out_value)
         )
     if self.total_ifb_value :
         pyk.fprint \
             ( self.out_format
             % ( self.ifb_type.name, "", "", "", self.ifb_type.abbr
               , self.total_ifb_value
               )
             )
Beispiel #39
0
    def create_ips_and_devices (self) :
        # devices and reserved nets from hna table
        for ip4 in self.olsr_hna.by_dest.iterkeys () :
            for n in self.ip4nets.iterkeys () :
                if ip4 in n :
                    break
            else :
                # only subnets of one of our ip4nets
                if self.verbose :
                    pyk.fprint ("HNA: %s not in our networks" % ip4)
                continue
            if ip4.mask == 32 :
                if ip4 not in self.olsr_nodes :
                    ip = self.ip_by_ip [ip4]
                    if ip.id_devices :
                        d = self.cons_dev [ip.id_devices]
                        d.hna = True
                    else :
                        # FIXME: Reserve network in database
                        self.rsrvd_nets [ip4] = True
            else :
                # FIXME: Reserve network in database
                self.rsrvd_nets [ip4] = True
                for i in ip4 :
                    assert i not in self.olsr_nodes
                    assert i not in self.rev_mid
        if self.verbose :
            for k in self.rsrvd_nets.iterkeys () :
                pyk.fprint ("HNA route to: %s" % k)
        if self.debug :
            for ip4 in self.olsr_hna.by_dest :
                for nw in self.ip4nets.iterkeys () :
                    if ip4 in nw :
                        pyk.fprint ("HNA: %s" % ip4)

        for dev in self.cons_dev.itervalues () :
            if dev.merged :
                continue
            dev.create ()
Beispiel #40
0
    def create_ips_and_devices(self):
        # devices and reserved nets from hna table
        for ip4 in self.olsr_hna.by_dest.iterkeys():
            for n in self.ip4nets.iterkeys():
                if ip4 in n:
                    break
            else:
                # only subnets of one of our ip4nets
                if self.verbose:
                    pyk.fprint("HNA: %s not in our networks" % ip4)
                continue
            if ip4.mask == 32:
                if ip4 not in self.olsr_nodes:
                    ip = self.ip_by_ip[ip4]
                    if ip.id_devices:
                        d = self.cons_dev[ip.id_devices]
                        d.hna = True
                    else:
                        # FIXME: Reserve network in database
                        self.rsrvd_nets[ip4] = True
            else:
                # FIXME: Reserve network in database
                self.rsrvd_nets[ip4] = True
                for i in ip4:
                    assert i not in self.olsr_nodes
                    assert i not in self.rev_mid
        if self.verbose:
            for k in self.rsrvd_nets.iterkeys():
                pyk.fprint("HNA route to: %s" % k)
        if self.debug:
            for ip4 in self.olsr_hna.by_dest:
                for nw in self.ip4nets.iterkeys():
                    if ip4 in nw:
                        pyk.fprint("HNA: %s" % ip4)

        for dev in self.cons_dev.itervalues():
            if dev.merged:
                continue
            dev.create()
Beispiel #41
0
def _show(s):
    from _TFL.portable_repr import portable_repr
    result = portable_repr(s)
    pyk.fprint(result)
Beispiel #42
0
def _main (cmd) :
    ATAX.Command.load_config (cmd)
    Fahrtenbuch_P.km_geld = cmd.km_geld
    fb = Fahrtenbuch_P.from_file (cmd.user, cmd.fahrtenbuch)
    pyk.fprint (fb.tex ())
Beispiel #43
0
def _main(cmd):
    rtsp = Relative_To_Search_Path(cmd.search_path)
    pyk.fprint(*(rtsp(p) for p in cmd.argv), sep=cmd.Sep)
Beispiel #44
0
 def send (self, from_addr, to_addrs, msg, mail_opts = None, rcpt_opts = None) :
     pyk.fprint \
         ( "Email via", self.mail_host, "from", from_addr, "to"
         , portable_repr (to_addrs), "\n"
         )
     pyk.fprint (pyk.decoded (msg, self.charset))
Beispiel #45
0
def _main(cmd):
    ATAX.Command.load_config(cmd)
    Fahrtenbuch_P.km_geld = cmd.km_geld
    fb = Fahrtenbuch_P.from_file(cmd.user, cmd.fahrtenbuch)
    pyk.fprint(fb.tex())
Beispiel #46
0
    def build_device_structure(self):
        for n in self.contents['nodes']:
            self.node_by_id[n.id] = n
        for d in self.contents['devices']:
            if d.id_nodes not in self.dev_by_node:
                self.dev_by_node[d.id_nodes] = []
            self.dev_by_node[d.id_nodes].append(d)
            self.cons_dev[d.id] = Consolidated_Device(self, d)
        for ip in self.contents['ips']:
            self.ip_by_ip[IP4_Address(ip.ip)] = ip
            if ip.id_devices:
                did = ip.id_devices
                self.cons_dev[did].add_redeemer_ip(ip)
            net = IP4_Address(ip.ip, ip.cidr)
            if net not in self.ip4nets:
                pyk.fprint("WARN: Adding network reservation: %s" % net)
                self.ip4nets[net] = True
        # consistency check of olsr data against redeemer db
        # check nodes from topology
        for ip4 in self.olsr_nodes:
            if ip4 not in self.ip_by_ip:
                pyk.fprint("WARN: ip %s from olsr topo not in ips" % ip4)
                del self.olsr_nodes[ip4]
        # check mid table
        midkey = []
        midtbl = {}
        for ip4, aliases in self.olsr_mid.iteritems():
            if ip4 not in self.ip_by_ip:
                pyk.fprint("WARN: key ip %s from olsr mid not in ips" % ip4)
                midkey.append(ip4)
            for a in aliases:
                if a not in self.ip_by_ip:
                    pyk.fprint("WARN: ip %s from olsr mid not in ips" % a)
                    if ip4 not in midtbl:
                        midtbl[ip4] = []
                    midtbl[ip4].append(a)
        assert not midkey
        for k, v in midtbl.iteritems():
            x = dict.fromkeys(self.olsr_mid[k])
            for ip4 in v:
                del x[ip4]
            self.olsr_mid[k] = x.keys()
        # consolidate devices using information from spider data
        node_by_sdev = {}
        for mainip, sdev in sorted(self.spider_devs.iteritems()):
            if sdev.done:
                continue
            sdev.done = True
            seen_ip = {}
            nodeid = None
            for sif in sorted(sdev.interfaces.itervalues()):
                assert not sif.done
                sif.done = True
                for in4 in sorted(sif.inet4):
                    if unroutable(in4.ip):
                        continue
                    seen_ip[in4.ip] = 1
                    i4 = IP4_Address(in4.ip)
                    ip = self.ip_by_ip.get(i4)
                    if not ip:
                        pyk.fprint \
                            ("WARN: ip %s from spider not in redeemer" % i4)
                        continue
                    if not ip.id_devices:
                        pyk.fprint("ERR: ip %s from spider has no device" % i4)
                        continue
                    d = self.cons_dev[ip.id_devices]
                    if sdev not in node_by_sdev:
                        node_by_sdev[sdev] = {}
                    if d.id_nodes not in node_by_sdev[sdev]:
                        node_by_sdev[sdev][d.id_nodes] = {}
                    if d.id not in node_by_sdev[sdev][d.id_nodes]:
                        node_by_sdev[sdev][d.id_nodes][d.id] = {}
                    node_by_sdev[sdev][d.id_nodes][d.id][in4.ip] = True
            assert mainip in seen_ip
        for sdev, nodes in sorted(node_by_sdev.iteritems()):
            if len(nodes) > 1:
                pyk.fprint \
                    ( "WARN: spider device %s expands to %s nodes: %s"
                    % ( sdev.mainip
                      , len (nodes)
                      , ', '.join
                        (self.node_by_id [n].name for n in nodes.iterkeys ())
                      )
                    )
            for n, devs in sorted(nodes.iteritems()):
                sdevs = {}
                sifs = {}
                dev1 = None
                err = False
                for devid, ips in sorted(devs.iteritems()):
                    d = self.cons_dev[devid]
                    if d.merged:
                        pyk.fprint \
                            ("ERR: %s already merged to %s" % (d, d.merged))
                        err = True
                        continue
                    if dev1 and d.id != dev1.id:
                        if self.verbose:
                            pyk.fprint \
                                ( "Spider %-15s: Merging device %s.%s to %s.%s"
                                % ( sdev.mainip
                                  , d.node.name
                                  , d.name
                                  , dev1.node.name
                                  , dev1.name
                                  )
                                )
                        assert dev1 != d
                        assert not dev1.merged
                        dev1.merge(d)
                    else:
                        dev1 = d
                    for ip in sorted(ips.iterkeys()):
                        sdevs[self.spider_devs[ip]] = True
                        if self.spider_iface[ip] not in sifs:
                            sifs[self.spider_iface[ip]] = {}
                        sifs[self.spider_iface[ip]][ip] = True

                if not err:
                    assert len(sdevs) == 1
                    if sdev not in sdevs:
                        pyk.fprint("ERR:  Merged interface differ:")
                        pyk.fprint("------------------------------")
                        pyk.fprint(sdevs.keys()[0].verbose_repr())
                        pyk.fprint("------------------------------")
                        pyk.fprint(sdev.verbose_repr())
                        pyk.fprint("------------------------------")
                    assert len(sifs) >= 1
                    assert dev1
                for sif, ips in sorted(sifs.iteritems()):
                    l = len(ips)
                    assert l >= 1
                    ifaces = {}
                    for ip in ips:
                        ifaces[ip] = dev1.interfaces[ip]
                    assert len(ifaces) == len(ips)
                    if1 = ip1 = None
                    for ip, ifc in sorted(ifaces.iteritems()):
                        if if1:
                            pyk.fprint \
                                ( "Spider %-15s: "
                                  "Merging iface %s.%s:%s to %s.%s:%s"
                                % ( sdev.mainip
                                  , d.node.name
                                  , d.name
                                  , ip
                                  , dev1.node.name
                                  , dev1.name
                                  , ip1
                                  )
                                )
                            if1.merge(ifc)
                        else:
                            if1 = ifc
                            ip1 = ip
                            if sif.is_wlan:
                                if1.is_wlan = True
                                if1.wlan_info = getattr(sif, 'wlan_info', None)
                            if1.names = sif.names
                            if1.spider_ip = sif.device.mainip
        # compound devices from mid table
        # We index nodes by mid-table entry (by the mid key-ip address)
        # for each mid entry there can be several nodes (config bug)
        for ip4, aliases in sorted(self.olsr_mid.iteritems()):
            nodes = {}
            ip = self.ip_by_ip[ip4]
            if ip.id_devices:
                d = self.cons_dev[ip.id_devices]
                d.mid_ip = ip4
                nodes[d.id_nodes] = d
            else:
                pyk.fprint("ERR:  key %s from mid has no device" % ip4)
            for a in sorted(aliases):
                ip = self.ip_by_ip[a]
                if not ip.id_devices:
                    pyk.fprint("ERR:  %s from mid %s has no device" % (a, ip4))
                    continue
                d = self.cons_dev[ip.id_devices]
                d.mid_ip = ip4
                if d.id_nodes not in nodes:
                    nodes[d.id_nodes] = d
                elif d != nodes[d.id_nodes]:
                    if d.merged:
                        if d.merged != nodes[d.id_nodes]:
                            pyk.fprint \
                                ( "ERR: %s already merged to %s "
                                  "not merging to %s"
                                % (d, d.merged, nodes [d.id_nodes])
                                )
                        continue
                    assert not nodes[d.id_nodes].merged
                    nodes[d.id_nodes].merge(d)
            if len(nodes) > 1:
                pyk.fprint \
                    ("WARN: mid %s expands to %s nodes" % (ip4, len (nodes)))
Beispiel #47
0
    def __init__(self, cmd, scope, debug=False):
        self.debug = debug
        self.verbose = cmd.verbose
        self.anonymize = cmd.anonymize
        if len(cmd.argv) > 0:
            f = open(cmd.argv[0])
        else:
            f = sys.stdin
        self.ip4nets = {}
        self.ip6nets = {}
        if cmd.network:
            for n in cmd.network:
                ip, comment = n.split(';', 1)
                if ':' in ip:
                    ip = IP6_Address(ip)
                    self.ip6nets[ip] = comment
                else:
                    ip = IP4_Address(ip)
                    self.ip4nets[ip] = comment
        olsr = get_olsr_container(cmd.olsr_file)
        self.olsr_nodes = {}
        for t in olsr.topo.forward.iterkeys():
            self.olsr_nodes[t] = True
        for t in olsr.topo.reverse.iterkeys():
            self.olsr_nodes[t] = True
        self.olsr_mid = olsr.mid.by_ip
        self.olsr_hna = olsr.hna
        self.rev_mid = {}
        for k, v in self.olsr_mid.iteritems():
            if k not in self.olsr_nodes:
                pyk.fprint("WARN: MIB %s: not in OLSR Topology" % k)
            #assert k in self.olsr_nodes
            for mid in v:
                assert mid not in self.rev_mid
                self.rev_mid[mid] = True
        self.spider_info = pickle.load(open(cmd.spider_dump, 'rb'))
        self.spider_devs = {}
        self.spider_iface = {}
        for ip, dev in self.spider_info.iteritems():
            if self.verbose:
                pyk.fprint("IP:", ip)
            # ignore spider errors
            if not isinstance(dev, Guess):
                continue
            dev.mainip = ip
            dev.done = False
            for iface in dev.interfaces.itervalues():
                iface.done = False
                for ip4 in iface.inet4:
                    i4 = ip4.ip
                    # ignore rfc1918, link local, localnet
                    if unroutable(i4):
                        continue
                    if (i4 in self.spider_devs
                            and self.spider_devs[i4] != dev):
                        pyk.fprint("WARN: Device %s/%s not equal:" % (ip, i4))
                        pyk.fprint("=" * 60)
                        pyk.fprint(dev.verbose_repr())
                        pyk.fprint("-" * 60)
                        pyk.fprint(self.spider_devs[i4].verbose_repr())
                        pyk.fprint("=" * 60)
                    elif (i4 in self.spider_iface
                          and self.spider_iface[i4] != iface):
                        assert dev == self.spider_devs[i4]
                        spif = self.spider_iface[i4]
                        pyk.fprint \
                            ( "WARN: Interfaces %s/%s of dev-ip %s share ip %s"
                            % (iface.name, spif.name, ip, i4)
                            )
                        spif.names.append(iface.name)
                        if iface.is_wlan:
                            spif.is_wlan = iface.is_wlan
                            spif.wlan_info = getattr(iface, 'wlan_info', None)
                        if self.verbose:
                            pyk.fprint("=" * 60)
                            pyk.fprint(iface)
                            pyk.fprint(spif)
                            pyk.fprint("-" * 60)
                            pyk.fprint(dev.verbose_repr())
                            pyk.fprint("=" * 60)
                        iface = spif
                    self.spider_devs[i4] = dev
                    self.spider_iface[i4] = iface
                    iface.device = dev
            if ip not in self.spider_devs:
                pyk.fprint("WARN: ip %s not in dev" % ip)
                if self.verbose:
                    pyk.fprint("=" * 60)
                    pyk.fprint(dev.verbose_repr())
                    pyk.fprint("=" * 60)
                name = 'unknown'
                assert name not in dev.interfaces
                iface = Interface(4711, name)
                iface.done = False
                dev.interfaces[name] = iface
                iface.device = dev
                iface.append_inet4(Inet4(ip, None, None, iface=name))
                self.spider_iface[ip] = iface
                self.spider_devs[ip] = dev

        self.scope = scope
        self.ffm = self.scope.FFM
        self.pap = self.scope.GTW.OMP.PAP
        self.mentor = {}
        self.rsrvd_nets = {}
        self.ffm_node_by_id = {}
        self.node_by_id = {}
        self.ip_by_ip = {}
        self.email_ids = {}
        self.phone_ids = {}
        self.person_by_id = {}
        self.member_by_id = {}
        self.dev_by_node = {}
        self.cons_dev = {}

        self.parser         = SQL_Parser \
            (verbose = False, fix_double_encode = True)
        self.parser.parse(f)
        self.contents = self.parser.contents
        self.tables = self.parser.tables
Beispiel #48
0
 def create_nodes(self):
     scope = self.scope
     for n in self.contents['nodes']:
         if len(scope.uncommitted_changes) > 100:
             scope.commit()
         gps = None
         if n.gps_lat_deg is None:
             assert n.gps_lat_min is None
             assert n.gps_lat_sec is None
             assert n.gps_lon_deg is None
             assert n.gps_lon_min is None
             assert n.gps_lon_sec is None
         elif n.gps_lat_min is None:
             assert n.gps_lat_sec is None
             assert n.gps_lon_min is None
             assert n.gps_lon_sec is None
             if self.anonymize:
                 lat = "%2.2f" % n.gps_lat_deg
                 lon = "%2.2f" % n.gps_lon_deg
             else:
                 lat = "%f" % n.gps_lat_deg
                 lon = "%f" % n.gps_lon_deg
             gps = dict(lat=lat, lon=lon)
         else:
             assert n.gps_lat_deg == int(n.gps_lat_deg)
             assert n.gps_lat_min == int(n.gps_lat_min)
             assert n.gps_lon_deg == int(n.gps_lon_deg)
             assert n.gps_lon_min == int(n.gps_lon_min)
             lat = "%d d %d m" % (int(n.gps_lat_deg), int(n.gps_lat_min))
             lon = "%d d %d m" % (int(n.gps_lon_deg), int(n.gps_lon_min))
             if n.gps_lat_sec is not None:
                 lat = lat + " %f s" % n.gps_lat_sec
             if n.gps_lon_sec is not None:
                 lon = lon + " %f s" % n.gps_lon_sec
             gps = dict(lat=lat, lon=lon)
             if self.anonymize:
                 lat = n.gps_lat_deg + n.gps_lat_min + (n.gps_lat_sec or 0)
                 lon = n.gps_lon_deg + n.gps_lon_min + (n.gps_lon_sec or 0)
                 gps = dict(lat="%2.2f" % lat, lon="%2.2f" % lon)
         id = self.person_dupes.get(n.id_members, n.id_members)
         owner = self.person_by_id.get(id)
         if self.anonymize:
             manager = owner
             owner = None
         elif not isinstance(owner, self.pap.Person):
             assert len(owner.actor) == 1
             manager = iter(owner.actor).next()
         elif id in self.companies or id in self.associations:
             manager = owner
             assert len(manager.acts_for) == 1
             owner = iter(manager.acts_for).next()
         elif n.id_tech_c and n.id_tech_c != n.id_members:
             manager = self.person_by_id.get(n.id_tech_c)
             assert (manager)
             pyk.fprint("INFO: Tech contact found: %s" % n.id_tech_c)
         else:
             manager = owner
             owner = None
         # node with missing manager has devices, use 0xff admin as owner
         if not manager and n.id in self.dev_by_node:
             manager = self.person_by_id.get(1)
             pyk.fprint \
                 ( "WARN: Node %s: member %s not found, using 1"
                 % (n.id, n.id_members)
                 )
         if manager:
             node = self.ffm.Node \
                 ( name        = n.name
                 , position    = gps
                 , show_in_map = n.map
                 , manager     = manager
                 , owner       = owner
                 , raw         = True
                 )
             self.set_last_change(node, n.changed, n.created)
             assert (node)
             self.ffm_node_by_id[n.id] = node
         else:
             pyk.fprint \
                 ( "ERR:  Node %s: member %s not found"
                 % (n.id, n.id_members)
                 )
Beispiel #49
0
 def create_persons(self):
     # FIXME: Set role for person so that person can edit only their
     # personal data, see self.person_disable
     scope = self.scope
     for m in sorted(self.contents['members'], key=lambda x: x.id):
         if len(scope.uncommitted_changes) > 100:
             scope.commit()
         self.member_by_id[m.id] = m
         if m.id == 309 and m.street.startswith("'"):
             m.street = m.street[1:]
         if m.id in self.person_remove:
             pyk.fprint \
                 ( "INFO: removing person %s %s %s"
                 % (m.id, m.firstname, m.lastname)
                 )
             continue
         if m.id in self.person_dupes:
             pyk.fprint \
                 ( "INFO: skipping person %s (duplicate of %s)"
                 % (m.id, self.person_dupes [m.id])
                 )
             continue
         if not m.firstname and not m.lastname:
             pyk.fprint("WARN: skipping person, no name:", m.id)
             continue
         if not m.lastname:
             pyk.fprint("WARN: skipping person, no lastname: %s" % m.id)
             continue
         cls = self.pap.Person
         name = ' '.join((m.firstname, m.lastname))
         pd = dict(name=name)
         if m.id in self.company_actor:
             cls = self.pap.Company
         elif m.id in self.association_actor:
             cls = self.pap.Association
         else:
             pd = dict(first_name=m.firstname, last_name=m.lastname)
         if self.anonymize:
             cls = self.pap.Person
             pd = dict(first_name=m.id, last_name='Funkfeuer')
         if self.verbose:
             type = cls.__name__.lower()
             pyk.fprint("Creating %s: %s" % (type, repr(name)))
         person = cls(raw=True, **pd)
         if m.id == 1:
             self.ff_subject = person
         if m.id not in self.rev_person_dupes:
             self.set_last_change(person, m.changed, m.created)
         self.person_by_id[m.id] = person
         if self.anonymize:
             continue
         self.try_insert_address(m, person)
         if m.email:
             self.try_insert_email(person, m)
         if m.fax and '@' in m.fax:
             self.try_insert_email(person, m, attr='fax')
             pyk.fprint \
                 ("INFO: Using email %s in fax field as email" % m.fax)
         if m.instant_messenger_nick:
             self.try_insert_im(m, person)
         for a, c in self.phone_types.iteritems():
             x = getattr(m, a)
             self.try_insert_phone(person, m, x, c)
         if m.mentor_id and m.mentor_id != m.id:
             self.mentor[m.id] = m.mentor_id
         if m.nickname:
             nick = self.pap.Nickname(m.nickname, raw=True)
             self.pap.Subject_has_Nickname(person, nick)
         if m.homepage:
             self.try_insert_url(m, person)
         if m.id in self.companies or m.id in self.associations:
             if m.id in self.companies:
                 cls = self.pap.Company
             if m.id in self.associations:
                 cls = self.pap.Association
             name = ' '.join((m.firstname, m.lastname))
             type = cls.__name__.lower()
             pyk.fprint("Creating %s: %s" % (type, repr(name)))
             legal = cls(name=name, raw=True)
             # copy property links over
             q = self.pap.Subject_has_Property.query
             for p in q(left=person).all():
                 self.pap.Subject_has_Property(legal, p.right)
             self.ffm.Person_acts_for_Legal_Entity(person, legal)
     if self.anonymize:
         return
     x = dict(self.company_actor)
     x.update(self.association_actor)
     for l_id, p_id in x.iteritems():
         person = self.person_by_id[p_id]
         legal = self.person_by_id[l_id]
         self.ffm.Person_acts_for_Legal_Entity(person, legal)
     for mentor_id, person_id in self.mentor.iteritems():
         mentor = self.person_by_id[mentor_id]
         person = self.person_by_id[person_id]
         self.ffm.Person_mentors_Person(mentor, person)
     # Retrieve info from dupe account
     for dupe, id in self.person_dupes.iteritems():
         # older version of db or dupe removed:
         if id not in self.person_by_id:
             continue
         d = self.member_by_id[dupe]
         m = self.member_by_id[id]
         person = self.person_by_id[id]
         changed = max \
             (d for d in (m.changed, d.changed, m.created, d.created) if d)
         created = min(m.created, d.created)
         self.set_last_change(person, changed, created)
         if d.email:
             self.try_insert_email(person, d, second=True)
         for a, c in self.phone_types.iteritems():
             x = getattr(d, a)
             self.try_insert_phone(person, d, x, c)
         if (d.mentor_id is not None and d.mentor_id != d.id
                 and d.mentor_id != id):
             assert (False)
         if d.nickname:
             nick = self.pap.Nickname(d.nickname, raw=True)
             self.pap.Subject_has_Nickname(person, nick)
         if d.homepage:
             self.try_insert_url(d, person)
         if d.instant_messenger_nick:
             self.try_insert_im(d, person)
         if dupe in self.merge_adr:
             self.try_insert_address(d, person)