Beispiel #1
0
def getCat(Cat, fid, icon):#checks if Category exists, creates if need be, then returns the Category to add Conference to
    if fid != '0': #If level is below root
        cursor = agenda.cursor()
        cursor.execute("select * from LEVEL where uid = \'" + fid + "\'")#gets parent LEVEL
        cp = cursor.fetchone()#gets parent info
        #cp[0]-uid, cp[1]-fid, cp[2]-level, cp[3]-title, cp[4]-cd, cp[5]-md, cp[6]-abstract, cp[7]-icon
        #cp[8]-stitle, cp[9]-visibility, cp[10]-modifyPassword, cp[11]-accessPassword, cp[12]-categorder
        if cp[1] == "delet":
            return None
        newCat = conference.Category()#creates Category with parents properties
        newCat.setName(cp[3])
        newCat.setDescription(cp[6])
        newCat.setOrder(cp[12])
        newCat.setVisibility(cp[9])
        newCat.setId(cp[0])
        catParent = getCat(newCat, cp[1], cp[7])#goes to fetch the parent category
    else:#If at root level get the root category
        catParent = conference.CategoryManager().getRoot()
    catlist = catParent.getSubCategoryList()#get list of subcategories already in category
    for tup in catlist:#checks if the category already exists and returns it
        if tup.name == Cat.name and tup.id == Cat.id:
            return tup
    #if category doesn't exist - create it
    catParent.newSubCategory(Cat)
    if icon != "":
        iconpath = Config.getInstance().getCategoryIconPath(Cat.getId())
        os.system("scp tbaron@%s:%s/%s.gif /tmp/%s.gif" % (file_host,hosticonpath,Cat.getId(),Cat.getId()))
        os.system("convert /tmp/%s.gif %s" % (Cat.getId(),iconpath))
    #get_transaction().commit()
    return Cat
Beispiel #2
0
 def testAddAndRemoveSubCategories(self):
     #checks that the conference counter works fine when adding a new
     #   sub-category
     croot=conference.Category()
     c1=conference.Category()
     c2=conference.Category()
     croot._addSubCategory(c2)
     creator=user.Avatar()
     conf0=conference.Conference(creator)
     conf0.setId("0")
     conf1=conference.Conference(creator)
     conf1.setId("1")
     c1._addConference(conf0)
     c1._addConference(conf1)
     self.assert_(croot.getNumConferences()==0)
     self.assert_(c1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==0)
     croot._addSubCategory(c1)
     self.assert_(croot.getNumConferences()==2)
     self.assert_(c1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==0)
     c1_1=conference.Category()
     c1._addSubCategory(c1_1)
     self.assert_(croot.getNumConferences()==2)
     self.assert_(c1.getNumConferences()==2)
     self.assert_(c1_1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==0)
     c1_1.move(c2)
     self.assert_(croot.getNumConferences()==2)
     self.assert_(c1.getNumConferences()==0)
     self.assert_(c1_1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==2)
     croot._removeSubCategory(c1)
     self.assert_(croot.getNumConferences()==2)
     self.assert_(c1.getNumConferences()==0)
     self.assert_(c1_1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==2)
     c2._removeSubCategory(c1_1)
     self.assert_(croot.getNumConferences()==0)
     self.assert_(c1.getNumConferences()==0)
     self.assert_(c1_1.getNumConferences()==2)
     self.assert_(c2.getNumConferences()==0)
Beispiel #3
0
 def testBasicAddAndRemoveConferences(self):
     #creation of basic category structure over which perform the tests
     croot=conference.Category()
     c1=conference.Category()
     croot._addSubCategory(c1)
     c2=conference.Category()
     croot._addSubCategory(c2)
     c1_1=conference.Category()
     c1._addSubCategory(c1_1)
     #checks adding a conference increases the conference number of the 
     #   involved categories
     creator=user.Avatar()
     conf1=conference.Conference(creator)
     conf1.setId("0")
     c1_1._addConference(conf1)
     self.assert_(c1_1.getNumConferences()==1)
     self.assert_(c1.getNumConferences()==1)
     self.assert_(c2.getNumConferences()==0)
     self.assert_(croot.getNumConferences()==1)
     conf2=conference.Conference(creator)
     conf2.setId("1")
     c2._addConference(conf2)
     self.assert_(c1_1.getNumConferences()==1)
     self.assert_(c1.getNumConferences()==1)
     self.assert_(c2.getNumConferences()==1)
     self.assert_(croot.getNumConferences()==2)
     c1_1.removeConference(conf1)
     self.assert_(c1_1.getNumConferences()==0)
     self.assert_(c1.getNumConferences()==0)
     self.assert_(c2.getNumConferences()==1)
     self.assert_(croot.getNumConferences()==1)
     c2.removeConference(conf2)
     self.assert_(c1_1.getNumConferences()==0)
     self.assert_(c1.getNumConferences()==0)
     self.assert_(c2.getNumConferences()==0)
     self.assert_(croot.getNumConferences()==0)
Beispiel #4
0
def getAgenda():
    print "migrating..."
    log("start getAgenda")
    cc = agenda.cursor()  #creates a new cursor to the database
    listcat = getAllSubCategories("171")
    strlistcat = "','".join(listcat)
    #cc.execute("select * from AGENDA where id='a052023'")
    #cc.execute("select * from AGENDA where fid in ('%s') and YEAR(cd)=2004 order by id"%strlistcat)#gets the AGENDAS
    #cc.execute("select * from AGENDA where fid in ('%s') and id>='' order by id"%strlistcat)#gets the AGENDAS
    #cc.execute("select * from AGENDA where fid = '296'")#gets the AGENDAS
    cc.execute(
        "select * from AGENDA where id > 'a015' and id < 'a02' order by id"
    )  #gets the AGENDAS
    #cc.execute("select * from AGENDA where id like 'a00%' and cd > '2000-12-01' ")#gets the AGENDAS
    #cc.execute("select * from AGENDA where id like 'a02%' and id >'a021094' order by id")
    #cc.execute("select * from AGENDA where id>='a045146' order by id")
    c = cc.fetchone()  #gets the next AGENDA
    cate = agenda.cursor()  #creates a cursor to get the LEVEL informaion
    #c[0]-title, c[1]-id, c[2]-stdate, c[3]-endate, c[4]-location, c[5]-nbsession, c[6]-chairman, c[7]-cem
    #c[8]-status, c[9]-an, c[10]-cd, c[11]-md, c[12]-stylesheet, c[13]-format, c[14]-confidentiality
    #c[15]-apassword, c[16]-repno, c[17]-fid, c[18]-acomments, c[19]-keywords, c[20]-visibility
    #c[21]-bld, c[22]-floor, c[23]-room, c[24]-stime, c[25]-etime
    #get CERN domain
    dh = domain.DomainHolder()
    CDom = None
    for dom in dh.getList():
        if dom.getName().upper() == "CERN":
            CDom = dom
    if not CDom:
        CDom = domain.Domain()
        CDom.setName("CERN")
        CDom.setDescription("CERN domain")
        CDom.addFiltersFromStr("128.141;128.142;137.138;192.91;194.12;192.16")
        dh.add(CDom)
        db.DBMgr.getInstance().commit()
    error = False
    ch = conference.ConferenceHolder()
    while c != None:
        #db.DBMgr.getInstance().startRequest()
        try:
            log("add conference : %s" % c[1])
            cate.execute(
                "select * from LEVEL where uid = \'" + c[17] +
                "\'")  #gets the name of the Category the conf belongs in
            catWanted = conference.Category(
            )  #creates Category that the AGENDA should belong to
            level = cate.fetchone()  #sets the category properties
            catWanted.setName(level[3])
            catWanted.setDescription(level[6])
            catWanted.setOrder(level[12])
            catWanted.setVisibility(level[9])
            catWanted.setId(level[0])
            category = getCat(
                catWanted, level[1], level[7]
            )  #checks to see if this category already exists - if not creates it
            if category == None:  #Conference is in a category to delete: don't add
                log("Conference %s not added, it's inside a 'to delete' category"
                    % c[1])
                db.DBMgr.getInstance().abort()
                c = cc.fetchone()
                continue
            user = getUser('CDS Agenda', '*****@*****.**', '',
                           '')  #creates a user representing creator
            try:
                cd = datetime(c[10].year, c[10].month, c[10].day)
            except:
                cd = datetime(1999, 1, 1)
            try:
                md = datetime(c[11].year, c[11].month, c[11].day)
            except:
                md = datetime(1999, 1, 1)
            try:
                conf = ch.getById(c[1])
            except:
                pass
            conf = category.newConference(
                user, c[1], cd, md)  #creates new Conference to map onto
            # update counter
            #year = c[1][1:3]
            #count = c[1][3:]
            #if count == "":
            #    count = 0
            #counterName = "CONFERENCE%s" % year
            #idxs = ch._getTree("counters")
            #if not idxs.has_key(counterName):
            #    idxs[counterName] = Counter()
            #idxs[counterName].sync(int(count))
            if c[8] == "close":
                conf.setClosed(True)
            conf.setTitle(c[0])
            conf.setDescription(c[18])
            if str(c[20]) == '0' or str(c[20]) == '':
                visibility = 999
            else:
                visibility = int(c[20])
            conf.setVisibility(visibility)
            startDate = datetime(c[2].year, c[2].month, c[2].day,
                                 int(c[24].seconds / 3600),
                                 int((c[24].seconds % 3600) / 60))
            endDate = None
            if c[3] != None:
                endDate = datetime(c[3].year, c[3].month, c[3].day,
                                   int(c[25].seconds / 3600),
                                   int((c[25].seconds % 3600) / 60))
            if not endDate or endDate <= startDate:
                endDate = datetime(c[2].year, c[2].month, c[2].day,
                                   int(c[24].seconds / 3600),
                                   int((c[24].seconds % 3600) / 60))
            conf.setDates(startDate, endDate)
            if c[4] != "0--":
                loc = conference.CustomLocation()
                loc.setName(c[4])
                conf.setLocation(loc)
        except (MaKaCError, AttributeError), e:
            log("Error : %s : conference not added" % e)
            c = cc.fetchone()  #gets the next conference
            error = True
        if not error:
            pw = genPW()  #generates random password
            if c[6] == None or c[6] == '\xa0':
                username = ''
            else:
                username = c[6]
            if c[7] == None:
                uemail = ''
            else:
                uemail = c[7]
            if uemail == '' or username.count(
                    " "
            ) >= max_white_space_in_names:  #if not full user details exist
                if username != '' or uemail != '':
                    if username != '':
                        chairtext = username
                    else:
                        chairtext = uemail
                    if uemail != '':
                        chairtext = "<a href=\"mailto:%s\">%s</a>" % (
                            uemail, chairtext)
                    conf.setChairmanText(chairtext)
            else:
                chair = getUser(username, uemail, '',
                                pw)  #creates the chairman user
                conf.addChair(chair)
            setType(c[12], conf.getId())  #sets the format of the agenda
            if c[13] == 'olist':  #facility to cope with this not in MaKaC
                pass  #set the format of talks to ordered list (A,B,C etc) rather than times
            if c[23] != "0--":
                loc = conference.CustomRoom()
                loc.setName(c[23])
                conf.setRoom(loc)
            cf = agenda.cursor()
            #gets the files associated with this conference
            cf.execute(
                "select * from FILE, FILE_EVENT where FILE.id = fileID and eventID = \'"
                + c[1] + "\'")
            f = cf.fetchone()  #gets the first file form the list
            while f != None:
                list = conf.getMaterialList()
                type = f[2]
                found = 0
                #if type in list get existing material
                for i in list:
                    if i.getTitle() == type:
                        found = 1
                        mat = i
                if found:
                    getFiles(mat, f)  #add resources to material
                else:  #if not then create new material with name 'type'
                    mat = conference.Material()
                    mat.setTitle(type)
                    conf.addMaterial(mat)
                    getFiles(mat, f)  #add resources to material
                f = cf.fetchone()  #get next file/resource
            if c[12] == "nosession":  #if there are no sessions look for contributions that go directly onto conference
                addToConf(c, conf)
            else:
                getSessions(
                    c, conf)  #gets the sessions belonging to this conference
            confId = conf.getId()
            # ACCESS CONTROL
            if c[14] == 'password':  #if conference is password protected creates and access user
                conf.setAccessKey(c[15])  #set the access password
                conf.setProtection(1)  #makes the conference restricted access
                #conf.grantAccess(colin)#grants access rights to me (for testing reasons)
            elif c[14] == 'cern-only':
                conf.requireDomain(CDom)
                log("added CERN domain")
            # MODIFICATION RIGHTS
            conf.setModifKey(c[9])  #add modification key
            log("Conference added : MaKaC ID : %s" % confId)
            # DEFAULT STYLE
            if c[12] in styles.keys():
                displayMgr.ConfDisplayMgrRegistery().getDisplayMgr(
                    conf).setDefaultStyle(styles[c[12]])
            else:
                displayMgr.ConfDisplayMgrRegistery().getDisplayMgr(
                    conf).setDefaultStyle("standard")
            c = cc.fetchone()  #gets the next conference
        else:
            error = False
            db.DBMgr.getInstance().commit()