示例#1
0
def prepare_main_form(self):

    db = database.Database(self.dbname)
    db.init()

    self.manufacturerBox.clear()
    set = db.get_man()
    set.append(u'')
    set.sort()
    self.manufacturerBox.addItems(set)

    self.symbolBox.clear()
    set = db.get_symbols()
    set.append(u'')
    set.sort()
    self.symbolBox.addItems(set)

    self.packageBox.clear()
    set = db.get_packages()
    set.append(u'')
    set.sort()
    self.packageBox.addItems(set)

    self.modelBox.clear()
    set = db.get_models()
    set.append(u'')
    set.sort()
    self.modelBox.addItems(set)

    db.close()
示例#2
0
def add_symbol(self):
    defaultpath = self.settings.option('DATA', 'repository')
    filename = QtGui.QFileDialog.getOpenFileName(
        self, 'Select .SCHLib file', defaultpath,
        'SCH Library File (*.schlib)')
    symbol = os.path.splitext(os.path.basename(unicode(filename)))[0].upper()

    if not symbol:
        return

    print symbol

    db = database.Database(self.dbname)

    if not db.get_symbol(symbol):
        db.set_symbol(symbol)

    db.close()

    prepare_main_form(self)
    index = self.symbolBox.findText(symbol)

    print index

    self.symbolBox.setCurrentIndex(index)
示例#3
0
def show_tables(self):
    db = database.Database(self.dbname)

    print 'COMPONENTS:'
    print db.query('SELECT * FROM components').fetchall()
    print 'PARAMETERS:'
    print db.query('SELECT * FROM parameters').fetchall()

    db.close()
def do_put_process(parent, data):

    result = data.id()

    #	print 'PUT', result

    db = database.Database('data/pyclient.db')

    try:
        db.set_element(data)
        db.commit()

    except Exception, e:
        print 'Error:', e
def do_export(parent, data):
    # обновление пользовательских источников данных

    db = database.Database('data/pyclient.db')

    for category in systemcategories:
        print 'CATEGORY:', category

        content = db.export(category)

        # костыль для полей Author локальных элементов
        for element in content:
            element['Author'] = element.get(
                'Author',
                parent.parent().settings.option('ACCOUNT', 'user'))

        print 'content', content
        result = sortupdate(category, content)

        if result:
            table, fieldlist, sorted = result

            print 'sorted', sorted

            #			tr = csvfile.CSVWriter()
            tr = msaccess.MDBWriter()
            tr.initialize()

            if tr.error:
                print 'ERROR'
                return tr.error

            tr.set(table, fieldlist, sorted)

            if tr.error:
                print 'ERROR', tr.error
                return tr.error


#			db.set_exported(category, content)
            db.commit()

    db.close()

    return 'Done'
示例#6
0
def add_package(self):
    defaultpath = self.settings.option('DATA', 'repository')
    filename = QtGui.QFileDialog.getOpenFileName(
        self, 'Select .PCBLib file', defaultpath,
        'PCB Library File (*.pcblib)')
    package = os.path.splitext(os.path.basename(unicode(filename)))[0].upper()

    if not package:
        return

    index = self.packageBox.findText(package)

    print index

    if index == -1:
        db = database.Database(self.dbname)
        db.set_package(package)
        db.close()
        self.packageBox.addItem(package)

    print self.packageBox.count()

    self.packageBox.setCurrentIndex(self.packageBox.count() - 1)
def do_upload(worker, data=None):

    db = database.Database('data/pyclient.db')

    data = db.get_upload()

    if not data:
        return 'Nothing to upload'

    application = worker.parent()

    tr = transport.Transport(worker.parent())

    request = objects.RequestMessage('identify')
    request.add_value('login',
                      application.settings.option('ACCOUNT', 'login', u'user'))
    request.add_value(
        'password', application.settings.option('ACCOUNT', 'password',
                                                u'user'))
    xmlrequest = request.build()

    xmlresponse = tr.send(xmlrequest,
                          'http://altiumlib.noxius.ru/?page=client&rem=read')

    response = objects.ResponseMessage(xmlresponse)
    response.parse()

    if response.error:
        print response.error
        return 'Parsing answer Error'

    if response.type == 'error':
        try:
            message = response.values['message']
        except:
            message = 'General Error'

        return message

    sessionid = response.values['sessionid']

    # формирование XML
    request = objects.RequestMessage('set_components')
    request.add_value('sessionid', sessionid)

    for element in data:
        request.add_item(element)

    xmlrequest = request.build()

    print xmlrequest

    # отправка XML
    application = worker.parent()
    xmlresponse = tr.send(
        xmlrequest,
        'http://altiumlib.noxius.ru/?page=client&rem=read&PHPSESSID=' +
        sessionid)

    # отмечаем отправленные компоненты
    #	for element in answer:
    #		db.set_sent(element)

    db.commit()
    db.close()

    return 'Uploaded %d components' % (len(data), )
def do_download(worker, data):
    # загрузка обновлений с сервера

    application = worker.parent()
    tr = transport.Transport(worker.parent())

    #	sessionid = application.settings.option('CONNECTION', 'sessionid')

    try:
        application.sessionid

    except AttributeError:
        request = objects.RequestMessage('identify')
        request.add_value(
            'login', application.settings.option('ACCOUNT', 'login', u'user'))
        request.add_value(
            'password',
            application.settings.option('ACCOUNT', 'password', u'user'))
        xmlrequest = request.build()

        xmlresponse = tr.send(
            xmlrequest, 'http://altiumlib.noxius.ru/?page=client&rem=read')

        print xmlresponse
        if not xmlresponse:
            return 'Communication error'

        response = objects.ResponseMessage(xmlresponse)
        response.parse()

        if response.error:
            print response.error
            return 'Parsing error'

        if response.type == 'error':
            try:
                message = response.values['message']
            except:
                message = 'General Error'

            return message


#		application.settings.set_option('CONNECTION', 'sessionid', sessionid)
        application.sessionid = response.values['sessionid']

    since = application.settings.option('DATA', 'lastupdate',
                                        datetime.datetime.min)

    request = objects.RequestMessage('get_components')
    request.add_value('sessionid', application.sessionid)
    request.add_value('since', since)

    xmlrequest = request.build()

    xmlresponse = tr.send(
        xmlrequest,
        'http://altiumlib.noxius.ru/?page=client&rem=read&PHPSESSID=' +
        application.sessionid)

    if not xmlresponse:
        return 'Communication error'

    response = objects.ResponseMessage(xmlresponse)
    response.parse()

    if response.type == 'error':
        print 'Error parsing response:', response.error
        return 'Error parsing response'

    application.settings.set_option('DATA', 'lastupdate',
                                    datetime.datetime.utcnow().isoformat(' '))

    if not response.data:
        print 'No data fetched'
        return 'Downloaded %d new components' % (len(response.data), )

    db = database.Database('data\pyclient.db')

    for element in response.data:
        db.set_element(element, sent=True)

    db.commit()
    db.close()

    return 'Downloaded %d new components' % (len(response.data), )
示例#9
0
def truncate_tables(self):
    db = database.Database(self.dbname)
    db.clear()

    db.close()