Esempio n. 1
0
def main():
    DBMgr.getInstance().startRequest()
    im = indexes.IndexesHolder()
    im.removeById("calendar")
    DBMgr.getInstance().commit()
    ch = CategoryManager()
    list = ch.getList()
    totnum = len(list)
    curnum = 0
    curper = 0
    for cat in list:
        committed = False
        DBMgr.getInstance().sync()
        calindex = im.getIndex("calendar")
        while not committed:
            try:
                del cat._calIdx
            except:
                pass
            for conf in cat.getConferenceList():
                calindex.indexConf(conf)
            try:
                DBMgr.getInstance().commit()
                committed = True
            except:
                DBMgr.getInstance().abort()
                print "retry %s" % cat.getId()
        curnum += 1
        per = int(float(curnum) / float(totnum) * 100)
        if per != curper:
            curper = per
            if per in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
                print "done %s%%" % per
    DBMgr.getInstance().endRequest()
Esempio n. 2
0
    def _getAnswer(self):

        import MaKaC.common.indexes as indexes
        nameIdx = indexes.IndexesHolder().getIndex('categoryName')

        try:
            query = ' AND '.join(map(lambda y: "*%s*" % y, filter(lambda x: len(x) > 0, self._searchString.split(' '))))
            foundEntries = nameIdx.search(query)
        except parsetree.ParseError:
            foundEntries = []

        number = len(foundEntries)

        # get only the first 10 results
        foundEntries = foundEntries[:7]

        entryNames = []

        for (categId, value) in foundEntries:
            categ = CategoryManager().getById(categId)
            entryNames.append({
                'title': categ.getTitle(),
                'path': self._getPath(categ),
                'url': str(urlHandlers.UHCategoryDisplay.getURL(categ))
                })

        return {
            "list": entryNames,
            "number": number
            }
Esempio n. 3
0
 def _process_DELETE(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category in self.user.favorite_categories:
         self.user.favorite_categories.remove(category)
         if redis_write_client:
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Esempio n. 4
0
def main():
    """
    This script deletes existing category indexes and recreates them.
    """

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    im = indexes.IndexesHolder()
    im.removeById('categoryDate')
    catIdx = im.getIndex('categoryDate')

    cm = CategoryManager()
    num_categs = len(cm._getIdx())
    cur_num = cur_percent = 0

    for cat in cm._getIdx().itervalues():
        for conf in cat.conferences.itervalues():
            catIdx.indexConf(conf)
        dbi.commit()

        cur_num += 1
        percent = int(float(cur_num) / num_categs * 100)
        if percent != cur_percent:
            cur_percent = percent
            print "{0}%".format(percent)
    dbi.endRequest()
Esempio n. 5
0
def main():
    """This script deletes existing category indexes and recreates them."""
    db.DBMgr.getInstance().startRequest()
    im = indexes.IndexesHolder()
    im.removeById('category')
    catIdx = im.getIndex('category')
    ch = CategoryManager()
    totnum = len(ch.getList())
    curnum = 0
    curper = 0
    for cat in ch.getList():
        while 1:
            try:
                for conf in cat.getConferenceList():
                    catIdx.indexConf(conf)
                transaction.commit()
                break
            except:
                db.DBMgr.getInstance().sync()
        curnum += 1
        per = int(float(curnum)/float(totnum)*100)
        if per != curper:
            curper = per
            print "%s%%" % per
    db.DBMgr.getInstance().endRequest()
Esempio n. 6
0
    def _getAnswer(self):

        import MaKaC.common.indexes as indexes
        nameIdx = indexes.IndexesHolder().getIndex('conferenceTitle')

        query = ' '.join(map(lambda y: "*%s*" % y, self._searchString.split()))
        foundEntries = nameIdx.search(query)

        number = len(foundEntries)

        # get only the first 10 results
        foundEntries = foundEntries[:7]

        entryTitles = []

        for (confId, value) in foundEntries:
            conference = CategoryManager().getById(confId)
            entryTitles.append({
                'title': conference.getTitle(),
                'url': str(urlHandlers.UHConferenceDisplay.getURL(conference))
                })

        return {
            "list": entryTitles,
            "number": number
            }
Esempio n. 7
0
    def _checkParams(self, params):

        base.RHProtected._checkParams(self, params)
        self._statusValue = "OK"
        self._message = ""
        try:
            self._title = params.get( "title", "" ).strip()
            self._startdate = params.get( "startdate", "" ).strip()
            self._enddate = params.get( "enddate", "" ).strip()
            self._place = params.get( "place", "" ).strip()
            self._room = params.get( "room", "" ).strip()
            self._accessPassword = params.get( "an", "" ).strip()
            self._modifyPassword = params.get( "mp", "" ).strip()
            self._style = params.get( "style", "" ).strip()
            self._fid = params.get( "fid", "" ).strip()
            self._description = params.get( "description", "" ).strip()
            self._stime = params.get( "stime", "" ).strip()
            self._etime = params.get( "etime", "" ).strip()
            self._speaker = params.get( "speaker", "" ).strip()
            self._speakeremail = params.get( "email", "" ).strip()
            self._speakeraffiliation = params.get( "affiliation", "" ).strip()
            if not self._title or not self._startdate or not self._enddate or not self._fid or not self._stime or not self._etime:
                raise MaKaCError( _("mandatory parameter missing"))
            ch = CategoryManager()
            try:
                self._cat = ch.getById(self._fid)
            except:
                raise MaKaCError( _("unknown category"))
        except MaKaCError, e:
          self._statusValue = "ERROR"
          self._message = e.getMsg()
Esempio n. 8
0
def main(argv):
    category = -1
    meeting = -1
    show = 0

    try:
        opts, args = getopt.getopt(argv, "hm:c:s", ["help", "meeting=", "category=", "show"])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-s", "--show"):
            show = 1
        elif opt in ("-m", "--meeting"):
            meeting = arg
        elif opt in ("-c", "--category"):
            category = arg

    # Create database instance and open trashcan manager object
    DBMgr.getInstance().startRequest()
    t = TrashCanManager()
    conf = None
    if show:
        for i in t.getList():
            if isinstance(i, Conference):
                if meeting != -1 and i.getId() == meeting:
                    print "[%s]%s" % (i.getId(), i.getTitle())
                elif meeting == -1:
                    print "[%s]%s" % (i.getId(), i.getTitle())
        sys.exit()
    if meeting != -1 and category != -1:
        print "Meeting:%s" % meeting
        print "Category:%s" % category
        for i in t.getList():
            if isinstance(i, Conference):
                if i.getId() == meeting:
                    conf = i
                    break

        if conf:
            # Remove the meeting from conference
            t.remove(conf)
            # Attach meeting to desired category
            cat = CategoryManager().getById(category)
            ConferenceHolder().add(conf)
            cat._addConference(conf)

            # Add Evaluation
            c = ConferenceHolder().getById(meeting)
            from MaKaC.evaluation import Evaluation

            c.setEvaluations([Evaluation(c)])

            DBMgr.getInstance().endRequest()
Esempio n. 9
0
 def _checkParams(self):
     if 'confId' in request.view_args:
         self.obj = self._conf = ConferenceHolder().getById(request.view_args['confId'])
         self.obj_type = 'event'
     elif 'categId' in request.view_args:
         self.obj = CategoryManager().getById(request.view_args['categId'])
         self.obj_type = 'category' if not self.obj.isRoot() else None
     else:
         self.obj = CategoryManager().getRoot()
         self.obj_type = None
Esempio n. 10
0
 def _process_PUT(self):
     category = CategoryManager().getById(request.view_args['category_id'])
     if category not in self.user.favorite_categories:
         if not category.canAccess(AccessWrapper(self.user.as_avatar)):
             raise Forbidden()
         self.user.favorite_categories.add(category)
         if redis_write_client:
             suggestions.unignore(self.user, 'category', category.getId())
             suggestions.unsuggest(self.user, 'category', category.getId())
     return jsonify(success=True)
Esempio n. 11
0
 def call(self):
     categ1 = CategoryManager().getById('1') #target category here
     for i in xrange(1, 0 + 1): #number of conferences to create here
         c = categ1.newConference(AvatarHolder().getById('1')) #creator of event
         c.setTitle("event " + str(i))
         c.setTimezone('UTC')
         c.setDates(nowutc() - timedelta(hours = i), nowutc() - timedelta(hours = i - 1))
         for j in xrange(1, 0+1): #number of bookings per event
             Catalog.getIdx("cs_bookingmanager_conference").get(c.getId()).createBooking("Vidyo", {"roomName":"room_"+str(i)+"_"+str(j),
                                                             "roomDescription": "test",
                                                             "owner":{"_type": "Avatar", "id":"1"}})
Esempio n. 12
0
def main():
    """This script deletes existing category indexes and recreates them."""
    db.DBMgr.getInstance().startRequest()
    ch = CategoryManager()
    for cat in ch.getList():
      for conf in cat.getConferenceList():
        chconf(conf)
      get_transaction().commit()
    # Tasks
    htl = timerExec.HelperTaskList.getTaskListInstance()
    for task in htl.getTasks():
        chtask(task)
    db.DBMgr.getInstance().endRequest()
Esempio n. 13
0
def get_excluded_categories():
    """Get all excluded category IDs"""
    from indico_livesync.plugin import LiveSyncPlugin
    todo = {x['id'] for x in LiveSyncPlugin.settings.get('excluded_categories')}
    excluded = set()
    while todo:
        category_id = todo.pop()
        try:
            category = CategoryManager().getById(category_id)
        except KeyError:
            continue
        excluded.add(category.getId())
        todo.update(category.subcategories)
    return excluded
Esempio n. 14
0
    def _process(self):
        matches = IndexesHolder().getIndex('categoryName').search(request.args['term'])
        results = []
        for category_id in matches[:7]:
            try:
                categ = CategoryManager().getById(category_id)
            except KeyError:
                continue
            results.append({
                'title': to_unicode(categ.getTitle()),
                'path': map(to_unicode, categ.getCategoryPathTitles()[1:-1]),
                'url': unicode(UHCategoryDisplay.getURL(categ))
            })

        return jsonify(success=True, results=results, count=len(matches))
Esempio n. 15
0
 def _process( self ):
     self._responseUtil.content_type = 'text/xml'
     cm = CategoryManager()
     try:
         XG = xmlGen.XMLGen()
         cat = cm.getById(self._id)
         self._getHeader(XG)
         self._getCategXML(cat, XG, self._fp)
         self._getFooter(XG)
         return XG.getXml()
     except:
         value = "ERROR"
         message = "Category does not exist"
     if value != "OK":
         return self._createResponse(value, message)
Esempio n. 16
0
def get_icons(detailed_data):
    icons = defaultdict(set)

    for __, day in detailed_data['events'].viewitems():
        for __, event in day:
            for categ_id in event.category_chain:
                if CategoryManager().getById(categ_id).getIcon():
                    icons[categ_id].add(event.id)
    return icons
Esempio n. 17
0
 def __init__(self, cal, day):
     self._calendar = cal
     self._day = day
     self._categories = set()
     for __, event in self._calendar._data['events'][self._day.date()]:
         for categ_id in event.category_chain:
             categ = CategoryManager().getById(categ_id)
             if categ in self._calendar._categList:
                 self._categories.add(categ)
Esempio n. 18
0
 def _getCategoryPath(id, aw):
     path = []
     firstCat = cat = CategoryManager().getById(id)
     visibility = cat.getVisibility()
     while cat:
         # the first category (containing the event) is always shown, others only with access
         iface = ICategoryMetadataFossil if firstCat or cat.canAccess(aw) else ICategoryProtectedMetadataFossil
         path.append(fossilize(cat, iface))
         cat = cat.getOwner()
     if visibility > len(path):
         visibilityName = "Everywhere"
     elif visibility == 0:
         visibilityName = "Nowhere"
     else:
         categId = path[visibility-1]["id"]
         visibilityName = CategoryManager().getById(categId).getName()
     path.reverse()
     path.append({"visibility": {"name": visibilityName}})
     return path
Esempio n. 19
0
 def call(self):
     categ1 = CategoryManager().getById('1')  #target category here
     for i in xrange(1, 0 + 1):  #number of conferences to create here
         c = categ1.newConference(
             AvatarHolder().getById('1'))  #creator of event
         c.setTitle("event " + str(i))
         c.setTimezone('UTC')
         c.setDates(nowutc() - timedelta(hours=i),
                    nowutc() - timedelta(hours=i - 1))
         for j in xrange(1, 0 + 1):  #number of bookings per event
             c.getCSBookingManager().createBooking(
                 "Vidyo", {
                     "roomName": "room_" + str(i) + "_" + str(j),
                     "roomDescription": "test",
                     "owner": {
                         "_type": "Avatar",
                         "id": "1"
                     }
                 })
Esempio n. 20
0
def initialize_new_db(root):
    """
    Initializes a new DB in debug mode
    """

    # Reset everything
    for e in root.keys():
        del root[e]

    # Delete whoosh indexes
    whoosh_dir = os.path.join(Config.getInstance().getArchiveDir(), 'whoosh')
    if os.path.exists(whoosh_dir):
        delete_recursively(whoosh_dir)

    # initialize db root
    cm = CategoryManager()
    cm.getRoot()

    return cm.getById('0')
Esempio n. 21
0
def initialize_new_db(root):
    """
    Initializes a new DB in debug mode
    """

    # Reset everything
    for e in root.keys():
        del root[e]

    # Delete whoosh indexes
    whoosh_dir = os.path.join(Config.getInstance().getArchiveDir(), 'whoosh')
    if os.path.exists(whoosh_dir):
        delete_recursively(whoosh_dir)

    # initialize db root
    cm = CategoryManager()
    cm.getRoot()

    return cm.getById('0')
Esempio n. 22
0
def guessProtection(fix=False, fromDate=None):
    """ Recreate deleted obj indices, from the DOH, guessing the protection,
    using the parent category"""

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    doh = DeletedObjectHolder()

    if fromDate:
        fromDateParsed_tz = datetime.datetime(
            *time.strptime(fromDate, '%Y-%m-%d')[:6],
            **{'tzinfo': timezone('UTC')})
        fromDateParsed_naive = datetime.datetime(
            *time.strptime(fromDate, '%Y-%m-%d')[:6])

    for obj in doh.getList():
        if fromDate:
            if obj.getOAIModificationDate().tzinfo:
                fromDateParsed = fromDateParsed_tz
            else:
                fromDateParsed = fromDateParsed_naive
            if obj.getOAIModificationDate() < fromDateParsed:
                continue

        if not hasattr(obj, 'protected'):
            try:
                categ = CategoryManager().getById(obj.getCategoryPath()[-1])
                obj.protected = categ.hasAnyProtection()

                print "-- protection for %s set as %s" % (prettyPrint(obj),
                                                          obj.protected)
            except KeyError:
                print ">> CATEGORY %s for %s no longer exists - assuming TRUE" % (
                    obj.getCategoryPath()[-1], prettyPrint(obj))
                obj.protected = True

            dbi.commit()
        else:
            print "** protection for %s was already at %s" % (prettyPrint(obj),
                                                              obj.protected)

    dbi.endRequest()
Esempio n. 23
0
def initialize_new_db(root):
    """
    Initializes a new DB in debug mode
    """

    # Reset everything
    for e in root.keys():
        del root[e]

    # initialize db root
    cm = CategoryManager()
    cm.getRoot()

    home = cm.getById('0')

    # set debug mode on
    minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
    minfo.setDebugActive(True)

    return home
Esempio n. 24
0
def initialize_new_db(root):
    """
    Initializes a new DB in debug mode
    """

    # Reset everything
    for e in root.keys():
        del root[e]

    # initialize db root
    cm = CategoryManager()
    cm.getRoot()

    home = cm.getById('0')

    # set debug mode on
    minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
    minfo.setDebugActive(True)

    return home
Esempio n. 25
0
 def object(self):
     from MaKaC.conference import CategoryManager
     if self.link_type == LinkType.category:
         return CategoryManager().getById(self.category_id, True)
     elif self.link_type == LinkType.event:
         return self.event_new
     elif self.link_type == LinkType.session:
         return self.session
     elif self.link_type == LinkType.contribution:
         return self.contribution
     elif self.link_type == LinkType.subcontribution:
         return self.subcontribution
Esempio n. 26
0
def get_suggested_categories(user):
    """Gets the suggested categories of a user for the dashboard"""
    from MaKaC.conference import CategoryManager

    if not redis_write_client:
        return []
    related = user.favorite_categories | user.get_linked_objects('category', 'manager')
    res = []
    for id_, score in suggestions.get_suggestions(user, 'category').iteritems():
        try:
            categ = CategoryManager().getById(id_)
        except KeyError:
            suggestions.unsuggest(user, 'category', id_)
            continue
        if not categ or categ.isSuggestionsDisabled() or categ in related:
            continue
        if any(p.isSuggestionsDisabled() for p in categ.iterParents()):
            continue
        if not categ.canAccess(AccessWrapper(user.as_avatar)):
            continue
        res.append({
            'score': score,
            'categ': categ,
            'path': truncate_path(categ.getCategoryPathTitles()[:-1], chars=50)
        })
    return res
Esempio n. 27
0
def updateCategsAndEvents():

    DBMgr.getInstance().startRequest()
    cm = CategoryManager()
    l = [cat.getId() for cat in cm.getList()]
    DBMgr.getInstance().endRequest()
    for id in l:
        DBMgr.getInstance().startRequest()
        cat = cm.getById(id)
        log("\nupdate category %s:%s"%(cat.getId(), cat.getName()))
        if cat.getId() in catTZMap.keys() and catTZMap[cat.getId()] :
            tz = catTZMap[cat.getId()]
            log("    found tz for this category: %s"%tz)
        else:
            tz = defTZ
            log("    use default tz: %s"%tz)
        cat.setTimezone(tz)
        updateCatTasks(cat)
        for conf in cat.getConferenceList():
            updateEvent(conf, tz)
            log("  conf %s: %s updated with tz: %s"%(conf.getId(), conf.getTitle(), tz))
        DBMgr.getInstance().endRequest()
Esempio n. 28
0
def guessProtection(fix=False,fromDate=None):

    """ Recreate deleted obj indices, from the DOH, guessing the protection,
    using the parent category"""

    dbi = DBMgr.getInstance()
    dbi.startRequest()

    doh = DeletedObjectHolder()

    if fromDate:
        fromDateParsed_tz = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6],**{'tzinfo':timezone('UTC')})
        fromDateParsed_naive = datetime.datetime(*time.strptime(fromDate,'%Y-%m-%d')[:6])

    for obj in doh.getList():
        if fromDate:
            if obj.getOAIModificationDate().tzinfo:
                fromDateParsed = fromDateParsed_tz
            else:
                fromDateParsed = fromDateParsed_naive
            if obj.getOAIModificationDate() < fromDateParsed:
                continue

        if not hasattr(obj, 'protected'):
            try:
                categ = CategoryManager().getById(obj.getCategoryPath()[-1])
                obj.protected = categ.hasAnyProtection()

                print "-- protection for %s set as %s" % (prettyPrint(obj), obj.protected)
            except KeyError:
                print ">> CATEGORY %s for %s no longer exists - assuming TRUE" % (obj.getCategoryPath()[-1], prettyPrint(obj))
                obj.protected = True

            dbi.commit()
        else:
            print "** protection for %s was already at %s" % (prettyPrint(obj), obj.protected)

    dbi.endRequest()
Esempio n. 29
0
def updateCalendarIndex():
    DBMgr.getInstance().startRequest()
    im = indexes.IndexesHolder()
    im.removeById('calendar')
    DBMgr.getInstance().commit()
    ch = CategoryManager()
    list = ch.getList()
    totnum = len(list)
    curnum = 0
    curper = 0
    for cat in list:
        committed = False
        DBMgr.getInstance().sync()
        calindex = im.getIndex('calendar')
        while not committed:
            try:
                del cat._calIdx
            except:
                pass
            for conf in cat.getConferenceList():
                try:
                    calindex.indexConf(conf)
                except Exception, e:
                    log("%s" % e)
                    log("calindex: exception indexing [%s] sd:%s, ed:%s" %
                        (conf.getId(), conf.getStartDate(), conf.getEndDate()))
            try:
                DBMgr.getInstance().commit()
                committed = True
            except:
                DBMgr.getInstance().abort()
                log("retry %s" % cat.getId())
        curnum += 1
        per = int(float(curnum) / float(totnum) * 100)
        if per != curper:
            curper = per
            if per in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
                log("done %s%%" % per)
Esempio n. 30
0
    def _getAnswer(self):

        import MaKaC.common.indexes as indexes
        nameIdx = indexes.IndexesHolder().getIndex('categoryName')

        query = ' '.join(map(lambda y: "*%s*" % y, self._searchString.split()))
        foundEntries = nameIdx.search(query, limit=7)
        number = len(foundEntries)

        entryNames = []

        for (categId, value) in foundEntries:
            categ = CategoryManager().getById(categId)
            entryNames.append({
                'title': categ.getTitle(),
                'path': self._getPath(categ),
                'url': str(urlHandlers.UHCategoryDisplay.getURL(categ))
                })

        return {
            "list": entryNames,
            "number": number
            }
Esempio n. 31
0
    def _getAnswer(self):

        import MaKaC.common.indexes as indexes
        nameIdx = indexes.IndexesHolder().getIndex('categoryName')

        query = ' '.join(map(lambda y: "*%s*" % y, self._searchString.split()))
        foundEntries = nameIdx.search(query, limit=7)
        number = len(foundEntries)

        entryNames = []

        for (categId, value) in foundEntries:
            categ = CategoryManager().getById(categId)
            entryNames.append({
                'title':
                categ.getTitle(),
                'path':
                self._getPath(categ),
                'url':
                str(urlHandlers.UHCategoryDisplay.getURL(categ))
            })

        return {"list": entryNames, "number": number}
def main():
    """This script deletes existing category indexes and recreates them."""
    dbi = db.DBMgr.getInstance()
    dbi.startRequest()
    im = indexes.IndexesHolder()
    im.removeById('categoryName')
    catIdx = im.getIndex('categoryName')
    ch = CategoryManager()
    totnum = len(ch.getList())
    curnum = 0
    curper = 0
    for cat in ch.getList():
        while 1:
            print cat.getId(), cat.getTitle()
            catIdx.index(cat.getId(), cat.getTitle().decode('utf-8'))
            dbi.commit()
            break
        curnum += 1
        per = int(float(curnum)/float(totnum)*100)
        if per != curper:
            curper = per
            print "%s%%" % per
    dbi.endRequest()
Esempio n. 33
0
def main():
    """This script deletes existing category indexes and recreates them."""
    dbi = db.DBMgr.getInstance()
    dbi.startRequest()
    im = indexes.IndexesHolder()
    im.removeById('categoryName')
    catIdx = im.getIndex('categoryName')
    ch = CategoryManager()
    totnum = len(ch.getList())
    curnum = 0
    curper = 0
    for cat in ch.getList():
        while 1:
            print cat.getId(), cat.getTitle()
            catIdx.index(cat.getId(), cat.getTitle().decode('utf-8'))
            dbi.commit()
            break
        curnum += 1
        per = int(float(curnum) / float(totnum) * 100)
        if per != curper:
            curper = per
            print "%s%%" % per
    dbi.endRequest()
Esempio n. 34
0
def updateCalendarIndex():
    DBMgr.getInstance().startRequest()
    im = indexes.IndexesHolder()
    im.removeById('calendar')
    DBMgr.getInstance().commit()
    ch = CategoryManager()
    list = ch.getList()
    totnum = len(list)
    curnum = 0
    curper = 0
    for cat in list:
        committed = False
        DBMgr.getInstance().sync()
        calindex = im.getIndex('calendar')
        while not committed:
            try:
                del cat._calIdx
            except:
                pass
            for conf in cat.getConferenceList():
                try:
                    calindex.indexConf(conf)
                except Exception,e:
                    log("%s"%e)
                    log("calindex: exception indexing [%s] sd:%s, ed:%s"%(conf.getId(),conf.getStartDate(), conf.getEndDate()))
            try:
                DBMgr.getInstance().commit()
                committed = True
            except:
                DBMgr.getInstance().abort()
                log("retry %s" % cat.getId())
        curnum += 1
        per = int(float(curnum)/float(totnum)*100)
        if per != curper:
            curper = per
            if per in [0,10,20,30,40,50,60,70,80,90,100]:
                log("done %s%%" % per)
Esempio n. 35
0
def reindexCategoryNameAndConferenceTitle(dbi, withRBDB, prevVersion):
    """
    Indexing Conference Title with new WhooshTextIndex
    """
    IndexesHolder().removeById('conferenceTitle')
    IndexesHolder().removeById('categoryName')
    confTitleIdx = IndexesHolder().getIndex('conferenceTitle')
    categNameIdx = IndexesHolder().getIndex('categoryName')
    dbi.commit()

    confTitleIdx.clear()
    confTitleIdx.initialize(dbi, ConferenceHolder().itervalues())

    categNameIdx.clear()
    categNameIdx.initialize(dbi, CategoryManager().itervalues())
Esempio n. 36
0
 def __init__(self, conference):
     if conference.getId() == "default":
         #Best values for CERN printing service
         self.__topMargin = 1.6
         self.__bottomMargin = 1.1
         self.__leftMargin = 1.6
         self.__rightMargin = 1.4
         self.__marginColumns = 1.0
         self.__marginRows = 0.0
         self._pageSize = "A4"
         self._landscape = False
         self._drawDashedRectangles = True
     else:
         from MaKaC.conference import CategoryManager
         defaultConferencePDFOptions = CategoryManager().getDefaultConference().getBadgeTemplateManager().getPDFOptions()
         self.__topMargin = defaultConferencePDFOptions.getTopMargin()
         self.__bottomMargin = defaultConferencePDFOptions.getBottomMargin()
         self.__leftMargin = defaultConferencePDFOptions.getLeftMargin()
         self.__rightMargin = defaultConferencePDFOptions.getRightMargin()
         self.__marginColumns = defaultConferencePDFOptions.getMarginColumns()
         self.__marginRows = defaultConferencePDFOptions.getMarginRows()
         self._pageSize = defaultConferencePDFOptions.getPagesize()
         self._landscape = defaultConferencePDFOptions.getLandscape()
         self._drawDashedRectangles = defaultConferencePDFOptions.getDrawDashedRectangles()
Esempio n. 37
0
def reindexCategoryNameAndConferenceTitle(dbi, prevVersion):
    """
    Indexing Conference Title with new WhooshTextIndex
    """
    IndexesHolder().removeById('conferenceTitle')
    IndexesHolder().removeById('categoryName')
    confTitleIdx = IndexesHolder().getIndex('conferenceTitle')
    categNameIdx = IndexesHolder().getIndex('categoryName')
    dbi.commit()

    iterator = (x[1] for x in console.conferenceHolderIterator(ConferenceHolder(), deepness='event'))
    confTitleIdx.clear()
    confTitleIdx.initialize(dbi, iterator)

    categNameIdx.clear()
    categNameIdx.initialize(dbi, CategoryManager().itervalues())
Esempio n. 38
0
    def _export(self, args):
        logger = _basicStreamHandler()

        if console.yesno("This will export all the data to the remote service "
                         "using the agent (takes LONG). Are you sure?"):
            try:
                agent = self._sm.getAllAgents()[args.agent]
            except KeyError:
                raise Exception("Agent '%s' was not found!" % args.agent)

            root = CategoryManager().getById(args.cat or 0)

            if args.monitor:
                monitor = open(args.monitor, 'w')
            else:
                monitor = None

            if args.fast:
                iterator = console.conferenceHolderIterator(
                    ConferenceHolder(), verbose=args.verbose)
            else:
                iterator = categoryIterator(root, 0, verbose=args.verbose)

            if args.output:
                nbatch = 0
                batch = []
                for record, rid, operation in _wrapper(_only_second(iterator),
                                                       agent._creationState,
                                                       self._dbi):
                    if len(batch) > SIZE_BATCH_PER_FILE:
                        self._writeFile(agent, args.output, nbatch, batch,
                                        logger)
                        nbatch += 1
                        batch = []

                    batch.append((record, rid, operation))

                if batch:
                    self._writeFile(agent, args.output, nbatch, batch, logger)
            else:
                agent._run(_wrapper(_only_second(iterator),
                                    agent._creationState, self._dbi),
                           logger=logger,
                           monitor=monitor)

            if monitor:
                monitor.close()
Esempio n. 39
0
    def __init__( self, aw, sDate, eDate, categList=[] ):
        self._aw = aw
        self._tz = sDate.tzinfo
        self._sDate = sDate.replace(hour=0, minute=0, second=0, microsecond=0)
        self._eDate = eDate.replace(hour=23, minute=59, second=59, microsecond=0)
        self._categList = categList
        self._icons = {}
        self._days = {}
        self._data = self.getData()
        self._conf_categories = defaultdict(set)
        categ_id_list = {c.id for c in self._categList}

        for day, data in self._data['events'].viewitems():
            for __, event in data:
                for categ_id in event.category_chain:
                    if str(categ_id) in categ_id_list:
                        categ = CategoryManager().getById(str(categ_id))
                        self._conf_categories[event.id].add(categ)
Esempio n. 40
0
 def linked_object(self):
     """Returns the linked object."""
     from MaKaC.conference import CategoryManager, ConferenceHolder
     if self.link_type == LinkType.category:
         return CategoryManager().getById(self.category_id, True)
     event = ConferenceHolder().getById(self.event_id, True)
     if event is None:
         return None
     if self.link_type == LinkType.event:
         return event
     elif self.link_type == LinkType.session:
         return event.getSessionById(self.session_id)
     elif self.link_type == LinkType.contribution:
         return event.getContributionById(self.contribution_id)
     elif self.link_type == LinkType.subcontribution:
         contribution = event.getContributionById(self.contribution_id)
         if contribution is None:
             return None
         return contribution.getSubContributionById(self.subcontribution_id)
Esempio n. 41
0
class RHSearch(RHCustomizable):
    """Performs a search using the search engine plugin"""
    def _checkParams(self):
        if 'confId' in request.view_args:
            self.obj = self._conf = ConferenceHolder().getById(request.view_args['confId'])
            self.obj_type = 'event'
        elif 'categId' in request.view_args:
            self.obj = CategoryManager().getById(request.view_args['categId'])
            self.obj_type = 'category' if not self.obj.isRoot() else None
        else:
            self.obj = CategoryManager().getRoot()
            self.obj_type = None

    def _process(self):
        with current_plugin.engine_plugin.plugin_context():
            form = current_plugin.search_form(prefix='search-', csrf_enabled=False)
            result = None
            if form.validate_on_submit():
                result = current_plugin.perform_search(form.data, self.obj)
            if isinstance(result, Response):  # probably a redirect or a json response
                return result
            view_class = WPSearchConference if isinstance(self.obj, Conference) else WPSearchCategory
            return view_class.render_template('results.html', self.obj, only_public=current_plugin.only_public,
                                              form=form, obj_type=self.obj_type, result=result)
Esempio n. 42
0
 def __init__(self, conference):
     if conference.getId() == "default":
         #Best values for CERN printing service
         self.__topMargin = 1.6
         self.__bottomMargin = 1.1
         self.__leftMargin = 1.6
         self.__rightMargin = 1.4
         self.__marginColumns = 1.0
         self.__marginRows = 0.0
         self._pageSize = "A4"
         self._landscape = False
         self._drawDashedRectangles = True
     else:
         from MaKaC.conference import CategoryManager
         defaultConferencePDFOptions = CategoryManager().getDefaultConference().getBadgeTemplateManager().getPDFOptions()
         self.__topMargin = defaultConferencePDFOptions.getTopMargin()
         self.__bottomMargin = defaultConferencePDFOptions.getBottomMargin()
         self.__leftMargin = defaultConferencePDFOptions.getLeftMargin()
         self.__rightMargin = defaultConferencePDFOptions.getRightMargin()
         self.__marginColumns = defaultConferencePDFOptions.getMarginColumns()
         self.__marginRows = defaultConferencePDFOptions.getMarginRows()
         self._pageSize = defaultConferencePDFOptions.getPagesize()
         self._landscape = defaultConferencePDFOptions.getLandscape()
         self._drawDashedRectangles = defaultConferencePDFOptions.getDrawDashedRectangles()
Esempio n. 43
0
 def getVars(self):
     vars = WBaseSearchBox.getVars(self)
     vars["categName"] = CategoryManager().getById(
         self._targetId).getTitle()
     vars['moreOptionsClass'] = "arrowExpandIcon"
     return vars
Esempio n. 44
0
        # something is wrong!
        sys.stderr.write("(l) '%s': expected %d, got %d! " %
                         (cid, expected, obtained))

        # fix it
        set_num_conferences(categ, expected)
        sys.stderr.write("[FIXED]\n")
        dbi.commit()


if __name__ == '__main__':
    dbi = DBMgr.getInstance()
    dbi.startRequest()

    confIndex = ConferenceHolder()._getIdx()
    index = CategoryManager()._getIdx()

    for cid, categ in index.iteritems():
        # conferece-containing categories
        if categ.conferences:

            # since we're here check consistency of TreeSet
            categ.conferences._check()

            lenConfs = 0
            for conf in categ.conferences:
                lenConfs += 1
                if conf.getId() not in confIndex:
                    sys.stderr.write("[%s] '%s' not in ConferenceHolder!\n" %
                                     (cid, conf.getId()))
## This file is part of Indico.
## Copyright (C) 2002 - 2012 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

from MaKaC.common import DBMgr
from MaKaC.conference import CategoryManager

DBMgr.getInstance().startRequest()
cm=CategoryManager()

cat=cm.getById('2l76')
conferences= cat.getAllConferenceList()
f = open("statusProtection.txt","w")
for conference in conferences:
    f.write(conference.getId() + " " + conference.getTitle() + " " + str(conference.isItselfProtected()) + " " + str(conference.isProtected())  + "\n")
f.close()
DBMgr.getInstance().endRequest()

Esempio n. 46
0
    ev = ConferenceHolder().getById('10235')
    updateEvent(ev)
    DBMgr.getInstance().commit()

DBMgr.getInstance().endRequest()

# reindex OAI
if 5 in execute:
    log("step 5/7: rebuild OAI index")
    updateOAIIndexes()

DBMgr.getInstance().startRequest()
# update default conference dates
if 2 in execute:
    log("step 2/7: update default event")
    defConf = CategoryManager().getDefaultConference()
    updateEvent(defConf)
    DBMgr.getInstance().commit()
DBMgr.getInstance().endRequest()

# reindex cal
if 6 in execute:
    log("step 6/7: rebuild calendar index")
    updateCalendarIndex()

#clean cache
if 7 in execute:
    log("step 7/7: clean cache")
    cleanCache()
log("end: %s" % str(datetime.now()))
Esempio n. 47
0
def runTests(host='localhost', port=FAKE_SERVICE_PORT,
             scenarios=[(2, 10)]):

    execTimes = []

    agent = InvenioBatchUploaderAgent('test1', 'test1', 'test',
                                      0, 'http://%s:%s' \
                                      % (host, port))

    ph = PluginsHolder()
    ph.reloadAllPlugins()
    ph.getPluginType('livesync').toggleActive()
    do = DummyObservable()

    do._notify('updateDBStructures', 'indico.ext.livesync',
                              None, None, None)

    sm = SyncManager.getDBInstance()

    sm.registerNewAgent(agent)

    cm = CategoryManager()

    avatar = user.Avatar()
    avatar.setName( "fake" )
    avatar.setSurName( "fake" )
    avatar.setOrganisation( "fake" )
    avatar.setLang( "en_GB" )
    avatar.setEmail( "*****@*****.**" )

    #registering user
    ah = user.AvatarHolder()
    ah.add(avatar)

    #setting up the login info
    li = user.LoginInfo( "dummyuser", "dummyuser" )
    ih = AuthenticatorMgr()
    userid = ih.createIdentity( li, avatar, "Local" )
    ih.add( userid )

    #activate the account
    avatar.activateAccount()

    #since the DB is empty, we have to add dummy user as admin
    minfo = HelperMaKaCInfo.getMaKaCInfoInstance()
    al = minfo.getAdminList()
    al.grant( avatar )

    dummy = avatar

    ContextManager.destroy()

    HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(DefaultConference())

    cm.getRoot()

    do._notify('requestStarted')

    home = cm.getById('0')

    # execute code
    for nconf in range(0, 1000):
        conf = home.newConference(dummy)
        conf.setTitle('Test Conference %s' % nconf)

    do._notify('requestFinished')

    time.sleep(1)

    # params won't be used
    task = LiveSyncUpdateTask(dateutil.rrule.MINUTELY)

    for scen in scenarios:

        print "Scenario %s workers, size = %s " % scen,

        # configure scenario
        InvenioBatchUploaderAgent.NUM_WORKERS = scen[0]
        InvenioBatchUploaderAgent.BATCH_SIZE = scen[1]

        ts = time.time()
        # just run it
        task.run()

        te = time.time()
        execTimes.append(te - ts)

        print "%s" % (te - ts)

        sm._track._pointers['test1'] = None

    for i in range(0, len(execTimes)):
        results[scenarios[i]] = execTimes[i]
Esempio n. 48
0
    def getBookings(self,
                    indexName,
                    viewBy,
                    orderBy,
                    minKey,
                    maxKey,
                    tz='UTC',
                    onlyPending=False,
                    conferenceId=None,
                    categoryId=None,
                    pickle=False,
                    dateFormat=None,
                    page=None,
                    resultsPerPage=None,
                    grouped=False):

        # TODO: Use iterators instead of lists

        if onlyPending:
            indexName += "_pending"

        reverse = orderBy == "descending"
        try:
            index = self.getIndex(indexName)
            totalInIndex = index.getCount()
            if categoryId and not CategoryManager().hasKey(categoryId) or conferenceId and \
                   not ConferenceHolder().hasKey(conferenceId):
                finalResult = QueryResult([], 0, 0, totalInIndex, 0)
            else:
                if viewBy == "conferenceTitle":
                    items, nBookings = index.getBookingsByConfTitle(
                        minKey, maxKey, conferenceId, categoryId)
                elif viewBy == "conferenceStartDate":
                    items, nBookings = index.getBookingsByConfDate(
                        minKey,
                        maxKey,
                        conferenceId,
                        categoryId,
                        tz,
                        dateFormat,
                        grouped=grouped)
                elif viewBy == "instanceDate":
                    items, nBookings = self._getBookingInstancesByDate(
                        indexName, dateFormat, minKey, maxKey)
                else:
                    items, nBookings = index.getBookingsByDate(
                        viewBy, minKey, maxKey, tz, conferenceId, categoryId,
                        dateFormat)

                if reverse:
                    items.reverse()

                nGroups = len(items)

                if page:
                    page = int(page)
                    if resultsPerPage:
                        resultsPerPage = int(resultsPerPage)
                    else:
                        resultsPerPage = 10

                    nPages = nGroups / resultsPerPage
                    if nGroups % resultsPerPage > 0:
                        nPages = nPages + 1

                    if page > nPages:
                        finalResult = QueryResult([], 0, 0, totalInIndex,
                                                  nPages)
                    else:
                        finalResult = QueryResult(
                            items[(page - 1) * resultsPerPage:page *
                                  resultsPerPage], nBookings, nGroups,
                            totalInIndex, nPages)

                else:
                    finalResult = QueryResult(items, nBookings, nGroups,
                                              totalInIndex, 0)

        except KeyError:
            Logger.get("VideoServ").warning(
                "Tried to retrieve index with name " + indexName +
                " but the index did not exist. Maybe no bookings have been added to it yet"
            )
            finalResult = QueryResult([], 0, 0, 0, 0)

        if CollaborationTools.hasCollaborationOption(
                "verifyIndexingResults"
        ) and CollaborationTools.getCollaborationOptionValue(
                "verifyIndexingResults"):
            finalResult.purgeNonExistingBookings()

        if pickle:
            # ATTENTION: this call silently changes the fossil map
            CollaborationTools.updateIndexingFossilsDict()
            return fossilize(finalResult, IQueryResultFossil, tz=tz)
        else:
            return finalResult
Esempio n. 49
0
def _category_id_set(target, value, *unused):
    from MaKaC.conference import CategoryManager
    cat = CategoryManager().getById(str(value))
    target.category_chain = map(int, reversed(cat.getCategoryPath()))
Esempio n. 50
0
 def category(self):
     from MaKaC.conference import CategoryManager
     return CategoryManager().getById(str(self.category_id),
                                      True) if self.category_id else None
Esempio n. 51
0
    if expected != obtained:
        # something is wrong!
        sys.stderr.write( "(l) '%s': expected %d, got %d! " % (cid, expected, obtained))

        # fix it
        set_num_conferences(categ, expected)
        sys.stderr.write("[FIXED]\n")
        dbi.commit()


if __name__ == '__main__':
    dbi = DBMgr.getInstance()
    dbi.startRequest()

    confIndex = ConferenceHolder()._getIdx()
    index = CategoryManager()._getIdx()

    for cid, categ in index.iteritems():
        # conferece-containing categories
        if categ.conferences:

            # since we're here check consistency of TreeSet
            categ.conferences._check()

            lenConfs = 0
            for conf in categ.conferences:
                lenConfs += 1
                if conf.getId() not in confIndex:
                    sys.stderr.write("[%s] '%s' not in ConferenceHolder!\n" % (cid, conf.getId()))

            # check event numbers
Esempio n. 52
0
def _category_id_set(target, value, *unused):
    from MaKaC.conference import CategoryManager
    cat = CategoryManager().getById(str(value))
    target.category_chain = map(int, reversed(cat.getCategoryPath()))
Esempio n. 53
0
 def buildIndex(self, dbi):
     self._idxCategItem = OOBTree()
     from MaKaC.conference import CategoryManager
     self.indexCateg(CategoryManager().getById('0'), dbi=dbi)
Esempio n. 54
0
from MaKaC.conference import CategoryManager
from MaKaC.webinterface.urlHandlers import UHCategoryDisplay, UHConferenceDisplay


def checkGroup (obj, group):
    ac = obj.getAccessController()
    if group in ac.allowed:
        return True
    return False

def showSubCategory(cat, group):
    if checkGroup(cat, group):
        print "%s - %s"%(cat.getName(), UHCategoryDisplay.getURL(cat))
    if cat.hasSubcategories():
        for subcat in cat.getSubCategoryList():
            showSubCategory(subcat,group)
    else:
        for conference in  cat.getConferenceList():
           if checkGroup(conference, group):
               print "%s - %s"%(conference.getName(), UHConferenceDisplay.getURL(conference))

DBMgr.getInstance().startRequest()
cm=CategoryManager()
cat=cm.getById("XXXX")
group = GroupHolder().getById("YYYYY")
showSubCategory(cat, group)


DBMgr.getInstance().endRequest()

Esempio n. 55
0
    for dom in catalog.dump():
        dh._getIdx()[dom.getId()] = dom
        count += 1
    print "[Done:%s]" % count


def migrateConferences(catalog):
    print "Migrating Conferences...",
    ch = ConferenceHolder()
    count = 0
    for conf in catalog.dump():
        ch._getIdx()[conf.getId()] = conf
        count += 1
    print "[Done:%s]" % count


from MaKaC.common import DBMgr

DBMgr.getInstance().startRequest()
root = DBMgr.getInstance().getDBConnection().root()
migrateAvatars(root["Catalogs"]["MaKaC.user.Avatar"])
migrateGroups(root["Catalogs"]["MaKaC.user.Group"])
migrateDomains(root["Catalogs"]["MaKaC.domain.Domain"])
migrateConferences(root["Catalogs"]["MaKaC.conference.Conference"])
del root["Catalogs"]
del root["_ic_registry"]
del root["first time"]
from MaKaC.conference import CategoryManager
CategoryManager().getRoot()._reIndex()
DBMgr.getInstance().endRequest()
Esempio n. 56
0
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

from indico.core.db import DBMgr
from MaKaC.user import Group
from MaKaC.conference import CategoryManager

DBMgr.getInstance().startRequest()
cm = CategoryManager()

catcounter = 0
mgrscounter = 0
notSendTo = {}
catList = []
rootCatList = []
rootCatList.append(cm.getById('1l28'))
rootCatList.append(cm.getById('1l30'))
for cat in rootCatList:
    for scat in cat.getSubCategoryList():
        catList.append(scat)

for cat in catList:
    ml = cat.getManagerList()
    if ml:
Esempio n. 57
0
## License, or (at your option) any later version.
##
## CDS Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

from MaKaC.common import DBMgr
from MaKaC.conference import CategoryManager, ConferenceHolder

DBMgr.getInstance().startRequest()
for cat in CategoryManager().getList():
    cat.getAccessController().setOwner(cat)

DBMgr.getInstance().endRequest()


def setConference(conf):
    conf.getAccessController().setOwner(conf)
    for mat in conf.getAllMaterialList():
        setMaterial(mat)
    for session in conf.getSessionList():
        setSession(session)
    for cont in conf.getContributionList():
        setContribution(cont)