Ejemplo n.º 1
0
 def startElement(self, name, attr):
     global telephoneDir
     if name == u'Подразделение':
         subdivision = telephonedir.Subdivision(
             attr.getValue(u'название').encode('utf-8'))
         if self.subdivisions:
             self.subdivisions[-1].addSubdivision(subdivision)
         self.subdivisions.append(subdivision)
     elif name == u'Сотрудник':
         collaborator = telephonedir.Collaborator(int(attr.getValue(u'кодСотрудника')),\
                                                   attr.getValue(u'фамилия').encode('utf-8'),\
                                                   attr.getValue(u'имя').encode('utf-8'),\
                                                   attr.getValue(u'отчество').encode('utf-8'))
         self.subdivisions[-1].add(collaborator)
         self.collaborators[collaborator.code] = collaborator
     elif name == u'ТелефонаТип':
         self.telephoneTypes[int(attr.getValue(u'кодТелефонаТип'))] = \
                             telephonedir.TelephoneType(attr.getValue(u'название').encode('utf-8'))
     elif name == u'Телефон':
         t = telephonedir.Telephone(
             attr.getValue(u'номер'),
             self.telephoneTypes[int(attr.getValue(u'кодТелефонаТип'))])
         self.telephones[int(attr.getValue(u'кодТелефона'))] = t
     elif name == u'ТелефонныйСправочник':
         telephoneDir = telephonedir.TelephoneDir(telephonedir.Telephones(telephonedir.TelephoneTypes()),\
                                                  self.subdivisions[0])
         for t in self.telephoneTypes.itervalues():
             telephoneDir.telephones.telephoneTypes.add(t)
         for t in self.telephones.itervalues():
             telephoneDir.telephones.add(t)
     elif name == u'Запись':
         r = telephonedir.TelephoneRecord(
             self.telephones[int(attr.getValue(u'кодТелефона'))],
             self.collaborators[int(attr.getValue(u'кодСотрудника'))])
         telephoneDir.add(r)
Ejemplo n.º 2
0
def load():
    subdivision = {}
    for rec in csv.reader(open(os.path.join(os.curdir, 'subdivision.csv'),
                               'rb'),
                          delimiter=';'):
        subdivision[rec[0]] = telephonedir.Subdivision(rec[0])
        if rec[1]:
            subdivision[rec[1]].addSubdivision(subdivision[rec[0]])
        else:
            telephoneDir = telephonedir.TelephoneDir(
                telephonedir.Telephones(telephonedir.TelephoneTypes()),
                subdivision[rec[0]])

    telephones, telephoneTypes, collaborators = {}, {}, {}
    for rec in csv.reader(open(os.path.join(os.curdir, 'ssu.csv'), 'rb'),
                          delimiter=';'):
        if rec[6] not in telephoneTypes:
            telephoneTypes[rec[6]] = telephonedir.TelephoneType(rec[6])
            telephoneDir.telephones.telephoneTypes.add(telephoneTypes[rec[6]])
        if rec[0] not in telephones:
            telephones[rec[0]] = telephonedir.Telephone(
                rec[0], telephoneTypes[rec[6]])
            telephoneDir.telephones.add(telephones[rec[0]])
        key = int(rec[1])
        if key not in collaborators:
            collaborators[key] = telephonedir.Collaborator(
                key, rec[2], rec[3], rec[4])
            subdivision[rec[5]].add(collaborators[key])
        telephoneDir.add(
            telephonedir.TelephoneRecord(telephones[rec[0]],
                                         collaborators[key]))

    return telephoneDir
Ejemplo n.º 3
0
FROM
  Телефоны"""
    telephones = {}
    try:
        curs.execute(sql)
        for rec in curs.fetchall():
            telephones[rec[0]] = telephonedir.Telephone(
                rec[2], telephoneTypes[rec[1]])
    except db.DatabaseError, x:
        print x
        conn.rollback()
    else:
        conn.commit()

    telephoneDir = telephonedir.TelephoneDir(
        telephonedir.Telephones(telephonedir.TelephoneTypes()), subdivision)
    for t in telephoneTypes.itervalues():
        telephoneDir.telephones.telephoneTypes.add(t)
    for t in telephones.itervalues():
        telephoneDir.telephones.add(t)

    sql = """
SELECT
  кодТелефона,
  кодСотрудника
FROM
  ТелефонныйСправочник"""
    try:
        curs.execute(sql)
        for rec in curs.fetchall():
            telephoneDir.add(