Ejemplo n.º 1
0
    def setUp(self):
        #initial information into temperory database
        self.user = User()
        self.user.username = "******"
        self.user.password = "******"
        self.user.email = "email"
        self.user.is_confirmed = True
        self.user.save()

        self.project = project()
        self.project.project_name = "project"
        self.project.creator = self.user
        self.project.save()
        
        self.chain1 = chain()
        self.chain1.name = "chain1"
        self.chain1.id = 1
        self.chain1.sequence = "1_2_3"
        self.chain1.project = self.project
        self.chain1.save()
        self.chain2 = chain()
        self.chain2.id = 2
        self.chain2.name = "chain2"
        self.chain2.sequence = ""
        self.chain2.project = self.project
        self.chain2.save()

        self.partObj1 = parts()
        self.partObj1.part_id = 1
        self.partObj1.part_name = "part1"
        self.partObj1.part_type = "type1"
        self.partObj1.save()
        self.partObj2 = parts()
        self.partObj2.part_id = 2
        self.partObj2.part_name = "part2"
        self.partObj2.part_type = "type2"
        self.partObj2.save()
        self.partObj3 = parts()
        self.partObj3.part_id = 3
        self.partObj3.part_name = "part3"
        self.partObj3.part_type = "type3"
        self.partObj3.save()
Ejemplo n.º 2
0
 def __init__(self):
     #attribute for analyse
     self.currentTag = ""
     self.currentAttribute = ""
     #choose the table
     self.isPart = 0
     #create the part object
     self.partTable = parts()
     #part table element
     self.part_id = ""
     self.ok = ""
     self.part_name = ""
     self.short_desc = ""
     self.description = ""
     self.part_type = ""
     self.author = ""
     self.status = ""
     self.dominant = ""
     self.discontinued = ""
     self.part_status = ""
     self.sample_status = ""
     self.p_status_cache = ""
     self.s_status_cache = ""
     self.creation_date = ""
     self.m_datetime = ""
     self.in_stock = ""
     self.results = ""
     self.favorite = ""
     self.specified_u_list = ""
     self.deep_u_list = ""
     self.deep_count = ""
     self.ps_string = ""
     self.scars = ""
     self.barcode = ""
     self.notes = ""
     self.source = ""
     self.nickname = ""
     self.premium = ""
     self.categories = ""
     self.sequence = ""
     self.seq_edit_cache = ""
     self.sequence_length = ""
Ejemplo n.º 3
0
def getPartInfo(partName):
    req = urllib2.Request(baseXmlUrl+partName)
    response = urllib2.urlopen(req)
    xmlStr = response.read()
    # analyse the xmlStr and save info to DB
    print 'getting part %s' % partName
    try:
        part_info = extractInfoFromXML(xmlStr)
    except:
        return None
    partObj = parts(part_id=part_info['id'], part_name=partName)
    partObj.part_type = part_info['part_type']
    partObj.short_desc = part_info['short_desc']
    partObj.author = part_info['part_author']
    partObj.sequence = part_info['sequence']
    partObj.deep_u_list = part_info['sub_part']
    partObj.deep_count = part_info['count']
    partObj.part_url = part_info['url']
    try:
        partObj.save()
        print 'part %s saved' % partObj.part_name
    except:
        print 'part %s error' % partObj.part_name
    return partObj
Ejemplo n.º 4
0
    def endElement(self,tag):
        if self.isPart == 1:
            if tag == "row":
                self.partTable.save()
                print "stored"
                self.partTable = parts()
            elif self.currentTag == "field" and self.currentAttribute == "part_id":
                self.partTable.part_id = int(self.part_id)
                print "part_id"+self.part_id
            elif self.currentTag == "field" and self.currentAttribute == "ok":
                if self.ok == "0":
                    self.partTable.ok = False
                elif self.ok == "1":
                    self.partTable.ok = True
                #print "self.ok" + self.ok
            elif self.currentTag == "field" and self.currentAttribute == "part_name":
                self.partTable.part_name = self.part_name
                print "self.part_name" + self.part_name
            elif self.currentTag == "field" and self.currentAttribute == "short_desc":
                self.partTable.short_desc = self.short_desc
                #print "self.short_desc" + self.short_desc
            elif self.currentTag == "field" and self.currentAttribute == "description":
                self.partTable.description = self.description
            elif self.currentTag == "field" and self.currentAttribute == "part_type":
                self.partTable.part_type = self.part_type
                #print "self.part_type" + self.part_type
            elif self.currentTag == "field" and self.currentAttribute == "author":
                self.partTable.author = self.author
                #print "self.author" + self.author
            elif self.currentTag == "field" and self.currentAttribute == "status":
                self.partTable.status = self.status
                #print "self.status" + self.status
            elif self.currentTag == "field" and self.currentAttribute == "dominant":
                if self.dominant == "0":
                    self.partTable.dominant = False
                elif self.dominant == "1":
                    self.partTable.dominant = True
                #print "self.dominant" + self.dominant
            elif self.currentTag == "field" and self.currentAttribute == "discontinued":
                if self.discontinued != "":
                    self.partTable.discontinued = int(self.discontinued)
                #print "self.discontinued" + self.discontinued
            elif self.currentTag == "field" and self.currentAttribute == "part_status":
                self.partTable.part_status = self.part_status
                #print "self.part_status" + self.part_status
            elif self.currentTag == "field" and self.currentAttribute == "sample_status":
                self.partTable.sample_status = self.sample_status
                #print "self.sample_status" + self.sample_status
            elif self.currentTag == "field" and self.currentAttribute == "p_status_cache":
                self.partTable.p_status_cache = self.p_status_cache
                #print "self.p_status_cache" + self.p_status_cache
            elif self.currentTag == "field" and self.currentAttribute == "s_status_cache":
                self.partTable.s_status_cache = self.s_status_cache
                #print "self.s_status_cache" + self.s_status_cache
            elif self.currentTag == "field" and self.currentAttribute == "creation_date":
                pass
                #if self.creation_date != "":
                #    print "origin date: " + self.creation_date
                #    str_split = self.creation_date.split('-')
                #    print str_split
                #    temp_date = datetime.date(int(str_split[0]),int(str_split[1]),int(str_split[2]))
                #    self.partTable.creation_date = temp_date
                #print "self.creation_date" + self.creation_date
            elif self.currentTag == "field" and self.currentAttribute == "m_datetime":
                pass
                #print "origin data: %s" % self.m_datetime
                #str_split = re.split('[- :]',self.m_datetime)
                #if str_split != [u'\t\t']:
                #    year = int(str_split[0])
                #    month = int(str_split[1])
                #    day = int(str_split[2])
                #    hour = int(str_split[3])
                #    minute = int(str_split[4])
                #    second = int(str_split[5])
                #    temp_date = datetime.datetime(year,month,day,hour,minute,second)
                    #print temp_date
                #    self.partTable.m_datetime = temp_date
                #print "self.m_datetime" + self.m_datetime

            elif self.currentTag == "field" and self.currentAttribute == "in_stock":
                if self.in_stock == "0":
                    self.partTable.in_stock = False
                elif self.in_stock == "1":
                    self.partTable.in_stock = True
                #print "self.in_stock" + self.in_stock
            elif self.currentTag == "field" and self.currentAttribute == "results":
                self.partTable.results = self.results
                #print "self.results" + self.results
            elif self.currentTag == "field" and self.currentAttribute == "favorite":
                if self.favorite != "":
                    self.partTable.favorite = int(self.favorite)
                #print "self.favorite" + self.favorite
            elif self.currentTag == "field" and self.currentAttribute == "specified_u_list":
                self.partTable.specified_u_list = self.specified_u_list
                #print "self.specified_u_list" + self.specified_u_list
            elif self.currentTag == "field" and self.currentAttribute == "deep_u_list":
                self.partTable.deep_u_list = self.deep_u_list
                #print "self.deep_u_list" + self.deep_u_list
            elif self.currentTag == "field" and self.currentAttribute == "deep_count":
                if self.deep_count != "":
                    self.partTable.deep_count = int(self.deep_count)
                #print "self.deep_count" + self.deep_count
            elif self.currentTag == "field" and self.currentAttribute == "ps_string":
                self.partTable.ps_string = self.ps_string
                #print "self.ps_string" + self.ps_string
            elif self.currentTag == "field" and self.currentAttribute == "scars":
                self.partTable.scars = self.scars
                #print "scars" + self.scars
            elif self.currentTag == "field" and self.currentAttribute == "barcode":
                self.partTable.barcode = self.barcode
                #print "barcode" + self.barcode
            elif self.currentTag == "field" and self.currentAttribute == "notes":
                self.partTable.notes = self.notes
                #print "notes" + self.notes
            elif self.currentTag == "field" and self.currentAttribute == "source":
                self.partTable.source = self.source
                #print "source" + self.source
            elif self.currentTag == "field" and self.currentAttribute == "nickname":
                self.partTable.nickname = self.nickname
                #print "nickname" + self.nickname
            elif self.currentTag == "field" and self.currentAttribute == "premium":
                self.partTable.premium = int(self.premium)
                #print "premium" + self.premium
            elif self.currentTag == "field" and self.currentAttribute == "categories":
                self.partTable.categories = self.categories
                #print "categories" + self.categories
            elif self.currentTag == "field" and self.currentAttribute == "sequence":
                self.partTable.sequence = self.sequence
                #print "sequence"
            elif self.currentTag == "field" and self.currentAttribute == "sequence_length":
                if self.sequence_length != "":
                    self.partTable.sequence_length = int(self.sequence_length)
                #print "sequence_length" + self.sequence_length

            #print self.currentTag
            #print "the read tag is: " + tag 
            self.currentTag = ""