def __getitem__(self, name):
     """See `ISourcePackageNameSet`."""
     name = ensure_unicode(name)
     try:
         return SourcePackageName.byName(name)
     except SQLObjectNotFound:
         raise NoSuchSourcePackageName(name)
예제 #2
0
 def __getitem__(self, name):
     """See `ISourcePackageNameSet`."""
     name = ensure_unicode(name)
     try:
         return SourcePackageName.byName(name)
     except SQLObjectNotFound:
         raise NoSuchSourcePackageName(name)
예제 #3
0
 def search(self, query, vocab_filter=None):
     """Return terms where query is a subtring of the name."""
     if query:
         clause = CONTAINSSTRING(self._table.q.name, ensure_unicode(query))
         if self._filter:
             clause = AND(clause, self._filter)
         return self._table.select(clause, orderBy=self._orderBy)
     return self.emptySelectResults()
예제 #4
0
 def search(self, query, vocab_filter=None):
     """Return terms where query is a subtring of the name."""
     if query:
         clause = CONTAINSSTRING(self._table.q.name, ensure_unicode(query))
         if self._filter:
             clause = AND(clause, self._filter)
         return self._table.select(clause, orderBy=self._orderBy)
     return self.emptySelectResults()
예제 #5
0
 def bulkAddActivity(self,
                     references,
                     result=BugWatchActivityStatus.SYNC_SUCCEEDED,
                     oops_id=None):
     """See `IBugWatchSet`."""
     bulk.create((BugWatchActivity.bug_watch_id, BugWatchActivity.result,
                  BugWatchActivity.oops_id),
                 [(bug_watch_id, result, ensure_unicode(oops_id))
                  for bug_watch_id in set(get_bug_watch_ids(references))])
예제 #6
0
 def bulkAddActivity(self, references,
                     result=BugWatchActivityStatus.SYNC_SUCCEEDED,
                     oops_id=None):
     """See `IBugWatchSet`."""
     bulk.create(
         (BugWatchActivity.bug_watch_id, BugWatchActivity.result,
          BugWatchActivity.oops_id),
         [(bug_watch_id, result, ensure_unicode(oops_id))
          for bug_watch_id in set(get_bug_watch_ids(references))])
예제 #7
0
    def searchForTerms(self, query=None, vocab_filter=None):
        if not query:
            return self.emptySelectResults()

        query = ensure_unicode(query).lower()
        clause = CONTAINSSTRING(self._table.q.name, query)
        if self._filter:
            clause = AND(clause, self._filter)
        results = self._table.select(clause, orderBy=self._orderBy)
        return self.iterator(results.count(), results, self.toTerm)
예제 #8
0
    def searchForTerms(self, query=None, vocab_filter=None):
        if not query:
            return self.emptySelectResults()

        query = ensure_unicode(query).lower()
        clause = CONTAINSSTRING(self._table.q.name, query)
        if self._filter:
            clause = AND(clause, self._filter)
        results = self._table.select(clause, orderBy=self._orderBy)
        return self.iterator(results.count(), results, self.toTerm)
예제 #9
0
    def searchForTerms(self, query=None, vocab_filter=None):
        if not query:
            return self.emptySelectResults()

        query = ensure_unicode(query).lower()
        results = IStore(self._table).find(
            self._table,
            self._table.name.contains_string(query),
            *self._clauses).order_by(self._order_by)
        return self.iterator(results.count(), results, self.toTerm)
예제 #10
0
    def ensure(self, name):
        """Ensure that the given BinaryPackageName exists, creating it
        if necessary.

        Returns the BinaryPackageName
        """
        name = ensure_unicode(name)
        try:
            return self[name]
        except NotFoundError:
            return self.new(name)
예제 #11
0
    def ensure(self, name):
        """Ensure that the given BinaryPackageName exists, creating it
        if necessary.

        Returns the BinaryPackageName
        """
        name = ensure_unicode(name)
        try:
            return self[name]
        except NotFoundError:
            return self.new(name)
예제 #12
0
    def __setitem__(self, key, value):
        key = ensure_unicode(key)
        pickled_value = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)

        self.session_data._ensureClientId()
        self.store.execute(
            "SELECT set_session_pkg_data(?, ?, ?, ?)",
            (self.session_data.client_id, self.product_id, key, pickled_value),
            noresult=True)

        # Store the value in the cache too
        self._data_cache[key] = value
예제 #13
0
 def __contains__(self, name):
     """See `IPillarNameSet`."""
     name = ensure_unicode(name)
     result = IStore(PillarName).execute("""
         SELECT TRUE
         FROM PillarName
         WHERE (id IN (SELECT alias_for FROM PillarName WHERE name=?)
                OR name=?)
             AND alias_for IS NULL
             AND active IS TRUE
         """, [name, name])
     return result.get_one() is not None
예제 #14
0
 def __contains__(self, name):
     """See `IPillarNameSet`."""
     name = ensure_unicode(name)
     result = IStore(PillarName).execute(
         """
         SELECT TRUE
         FROM PillarName
         WHERE (id IN (SELECT alias_for FROM PillarName WHERE name=?)
                OR name=?)
             AND alias_for IS NULL
             AND active IS TRUE
         """, [name, name])
     return result.get_one() is not None
예제 #15
0
    def search(self, text):
        """See `ILanguageSet`."""
        if text:
            text = ensure_unicode(text).lower()
            results = ISlaveStore(Language).find(
                Language,
                Or(Language.code.lower().contains_string(text),
                   Language.englishname.lower().contains_string(
                       text))).order_by(Language.englishname)
        else:
            results = None

        return results
예제 #16
0
 def search(self, query, vocab_filter=None):
     """Search for web bug trackers."""
     query = ensure_unicode(query).lower()
     results = IStore(self._table).find(
         self._table,
         And(
             self._filter, BugTracker.active == True,
             Or(CONTAINSSTRING(BugTracker.name, query),
                CONTAINSSTRING(BugTracker.title, query),
                CONTAINSSTRING(BugTracker.summary, query),
                CONTAINSSTRING(BugTracker.baseurl, query))))
     results = results.order_by(self._order_by)
     return results
예제 #17
0
    def __init__(self, session_data_container, client_id):
        self.session_data_container = session_data_container
        self.client_id = ensure_unicode(client_id)
        self.lastAccessTime = time.time()

        # Update the last access time in the db if it is out of date
        table_name = session_data_container.session_data_table_name
        query = """
            UPDATE %s SET last_accessed = CURRENT_TIMESTAMP
            WHERE client_id = ?
                AND last_accessed < CURRENT_TIMESTAMP - '%d seconds'::interval
            """ % (table_name, session_data_container.resolution)
        self.store.execute(query, (self.client_id,), noresult=True)
예제 #18
0
    def __setitem__(self, key, value):
        key = ensure_unicode(key)
        pickled_value = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)

        self.session_data._ensureClientId()
        self.store.execute(
            "SELECT set_session_pkg_data(?, ?, ?, ?)",
            (self.session_data.client_id,
                self.product_id, key, pickled_value),
            noresult=True)

        # Store the value in the cache too
        self._data_cache[key] = value
예제 #19
0
    def search(self, text):
        """See `ILanguageSet`."""
        if text:
            text = ensure_unicode(text).lower()
            results = ISlaveStore(Language).find(
                Language, Or(
                    Language.code.lower().contains_string(text),
                    Language.englishname.lower().contains_string(
                        text))).order_by(Language.englishname)
        else:
            results = None

        return results
예제 #20
0
    def __init__(self, session_data_container, client_id):
        self.session_data_container = session_data_container
        self.client_id = ensure_unicode(client_id)
        self.lastAccessTime = time.time()

        # Update the last access time in the db if it is out of date
        table_name = session_data_container.session_data_table_name
        query = """
            UPDATE %s SET last_accessed = CURRENT_TIMESTAMP
            WHERE client_id = ?
                AND last_accessed < CURRENT_TIMESTAMP - '%d seconds'::interval
            """ % (table_name, session_data_container.resolution)
        self.store.execute(query, (self.client_id, ), noresult=True)
예제 #21
0
    def __init__(self,
                 distroseries,
                 parents=(),
                 arches=(),
                 archindep_archtag=None,
                 packagesets=None,
                 rebuild=False,
                 overlays=(),
                 overlay_pockets=(),
                 overlay_components=()):
        self.distroseries = distroseries
        self.parent_ids = [int(id) for id in parents]
        # Load parent objects in bulk...
        parents_bulk = bulk.load(DistroSeries, self.parent_ids)
        # ... sort the parents to match the order in the 'parents' parameter.
        self.parents = sorted(
            parents_bulk, key=lambda parent: self.parent_ids.index(parent.id))
        self.arches = arches
        self.archindep_archtag = archindep_archtag
        if packagesets is None:
            self.packagesets_ids = None
            self.packagesets = None
        else:
            self.packagesets_ids = [
                ensure_unicode(packageset) for packageset in packagesets
            ]
            self.packagesets = bulk.load(
                Packageset, [int(packageset) for packageset in packagesets])
        self.rebuild = rebuild
        self.overlays = overlays
        self.overlay_pockets = overlay_pockets
        self.overlay_components = overlay_components
        self._store = IMasterStore(DistroSeries)

        self.first_derivation = (
            not self.distroseries.distribution.has_published_sources)

        if self.first_derivation:
            # Use-case #1.
            self.derivation_parents = self.parents
            self.derivation_parent_ids = self.parent_ids
        else:
            # Use-case #2.
            self.derivation_parents = [self.distroseries.previous_series]
            self.derivation_parent_ids = [
                p.id for p in self.derivation_parents if p is not None
            ]
            if self.parent_ids == []:
                self.parents = (
                    self.distroseries.previous_series.getParentSeries())
        self._create_source_names_by_parent()
예제 #22
0
 def search(self, query, vocab_filter=None):
     """Search for web bug trackers."""
     query = ensure_unicode(query).lower()
     results = IStore(self._table).find(
         self._table, And(
         self._filter,
         BugTracker.active == True,
         Or(
             CONTAINSSTRING(BugTracker.name, query),
             CONTAINSSTRING(BugTracker.title, query),
             CONTAINSSTRING(BugTracker.summary, query),
             CONTAINSSTRING(BugTracker.baseurl, query))))
     results = results.order_by(self._order_by)
     return results
예제 #23
0
    def getByName(self, name, ignore_inactive=False):
        """Return the pillar with the given name.

        If ignore_inactive is True, then only active pillars are considered.

        If no pillar is found, None is returned.
        """
        # We could attempt to do this in a single database query, but I
        # expect that doing two queries will be faster that OUTER JOINing
        # the Project, Product and Distribution tables (and this approach
        # works better with SQLObject too.

        # Retrieve information out of the PillarName table.
        query = """
            SELECT id, product, project, distribution
            FROM PillarName
            WHERE (id = (SELECT alias_for FROM PillarName WHERE name=?)
                   OR name=?)
                AND alias_for IS NULL%s
            LIMIT 1
            """
        if ignore_inactive:
            query %= " AND active IS TRUE"
        else:
            query %= ""
        name = ensure_unicode(name)
        result = IStore(PillarName).execute(query, [name, name])
        row = result.get_one()
        if row is None:
            return None

        assert len([column for column in row[1:] if column is None]) == 2, (
            "One (and only one) of product, project or distribution may be "
            "NOT NULL: %s" % row[1:])

        id, product, project, distribution = row

        if product is not None:
            return getUtility(IProductSet).get(product)
        elif project is not None:
            return getUtility(IProjectGroupSet).get(project)
        else:
            return getUtility(IDistributionSet).get(distribution)
예제 #24
0
    def getByName(self, name, ignore_inactive=False):
        """Return the pillar with the given name.

        If ignore_inactive is True, then only active pillars are considered.

        If no pillar is found, None is returned.
        """
        # We could attempt to do this in a single database query, but I
        # expect that doing two queries will be faster that OUTER JOINing
        # the Project, Product and Distribution tables (and this approach
        # works better with SQLObject too.

        # Retrieve information out of the PillarName table.
        query = """
            SELECT id, product, project, distribution
            FROM PillarName
            WHERE (id = (SELECT alias_for FROM PillarName WHERE name=?)
                   OR name=?)
                AND alias_for IS NULL%s
            LIMIT 1
            """
        if ignore_inactive:
            query %= " AND active IS TRUE"
        else:
            query %= ""
        name = ensure_unicode(name)
        result = IStore(PillarName).execute(query, [name, name])
        row = result.get_one()
        if row is None:
            return None

        assert len([column for column in row[1:] if column is None]) == 2, (
            "One (and only one) of product, project or distribution may be "
            "NOT NULL: %s" % row[1:])

        id, product, project, distribution = row

        if product is not None:
            return getUtility(IProductSet).get(product)
        elif project is not None:
            return getUtility(IProjectGroupSet).get(project)
        else:
            return getUtility(IDistributionSet).get(distribution)
예제 #25
0
    def __delitem__(self, key):
        """Delete an item.

        Note that this will never fail in order to avoid
        race conditions in code using the session machinery
        """
        try:
            del self._data_cache[key]
        except KeyError:
            # Not in the cache, then it won't be in the DB. Or if it is,
            # another process has inserted it and we should keep our grubby
            # fingers out of it.
            return
        query = """
            DELETE FROM %s WHERE client_id = ? AND product_id = ? AND key = ?
            """ % self.table_name
        self.store.execute(query,
                           (self.session_data.client_id, self.product_id,
                            ensure_unicode(key)),
                           noresult=True)
예제 #26
0
    def __delitem__(self, key):
        """Delete an item.

        Note that this will never fail in order to avoid
        race conditions in code using the session machinery
        """
        try:
            del self._data_cache[key]
        except KeyError:
            # Not in the cache, then it won't be in the DB. Or if it is,
            # another process has inserted it and we should keep our grubby
            # fingers out of it.
            return
        query = """
            DELETE FROM %s WHERE client_id = ? AND product_id = ? AND key = ?
            """ % self.table_name
        self.store.execute(
            query,
            (self.session_data.client_id,
                self.product_id, ensure_unicode(key)),
            noresult=True)
    def __init__(
        self, distroseries, parents=(), arches=(), archindep_archtag=None,
        packagesets=(), rebuild=False, overlays=(), overlay_pockets=(),
        overlay_components=()):
        self.distroseries = distroseries
        self.parent_ids = [int(id) for id in parents]
        # Load parent objects in bulk...
        parents_bulk = bulk.load(DistroSeries, self.parent_ids)
        # ... sort the parents to match the order in the 'parents' parameter.
        self.parents = sorted(
            parents_bulk,
            key=lambda parent: self.parent_ids.index(parent.id))
        self.arches = arches
        self.archindep_archtag = archindep_archtag
        self.packagesets_ids = [
            ensure_unicode(packageset) for packageset in packagesets]
        self.packagesets = bulk.load(
            Packageset, [int(packageset) for packageset in packagesets])
        self.rebuild = rebuild
        self.overlays = overlays
        self.overlay_pockets = overlay_pockets
        self.overlay_components = overlay_components
        self._store = IMasterStore(DistroSeries)

        self.first_derivation = (
            not self.distroseries.distribution.has_published_sources)

        if self.first_derivation:
            # Use-case #1.
            self.derivation_parents = self.parents
            self.derivation_parent_ids = self.parent_ids
        else:
            # Use-case #2.
            self.derivation_parents = [self.distroseries.previous_series]
            self.derivation_parent_ids = [
                p.id for p in self.derivation_parents if p is not None]
            if self.parent_ids == []:
                self.parents = (
                    self.distroseries.previous_series.getParentSeries())
        self._create_source_names_by_parent()
예제 #28
0
    def build_search_query(self, text, extra_columns=()):
        """Query parameters shared by search() and count_search_matches().

        :returns: Storm ResultSet object
        """
        # These classes are imported in this method to prevent an import loop.
        from lp.registry.model.product import Product
        from lp.registry.model.projectgroup import ProjectGroup
        from lp.registry.model.distribution import Distribution
        OtherPillarName = ClassAlias(PillarName)
        origin = [
            PillarName,
            LeftJoin(OtherPillarName,
                     PillarName.alias_for == OtherPillarName.id),
            LeftJoin(Product, PillarName.product == Product.id),
            LeftJoin(ProjectGroup, PillarName.project == ProjectGroup.id),
            LeftJoin(Distribution, PillarName.distribution == Distribution.id),
        ]
        conditions = SQL('''
            PillarName.active = TRUE
            AND (PillarName.name = lower(%(text)s) OR

                 Product.fti @@ ftq(%(text)s) OR
                 lower(Product.title) = lower(%(text)s) OR

                 Project.fti @@ ftq(%(text)s) OR
                 lower(Project.title) = lower(%(text)s) OR

                 Distribution.fti @@ ftq(%(text)s) OR
                 lower(Distribution.title) = lower(%(text)s)
                )
            ''' % sqlvalues(text=ensure_unicode(text)))
        columns = [
            PillarName, OtherPillarName, Product, ProjectGroup, Distribution
        ]
        for column in extra_columns:
            columns.append(column)
        return IStore(PillarName).using(*origin).find(tuple(columns),
                                                      conditions)
예제 #29
0
    def build_search_query(self, text, extra_columns=()):
        """Query parameters shared by search() and count_search_matches().

        :returns: Storm ResultSet object
        """
        # These classes are imported in this method to prevent an import loop.
        from lp.registry.model.product import Product
        from lp.registry.model.projectgroup import ProjectGroup
        from lp.registry.model.distribution import Distribution
        OtherPillarName = ClassAlias(PillarName)
        origin = [
            PillarName,
            LeftJoin(
                OtherPillarName, PillarName.alias_for == OtherPillarName.id),
            LeftJoin(Product, PillarName.product == Product.id),
            LeftJoin(ProjectGroup, PillarName.project == ProjectGroup.id),
            LeftJoin(
                Distribution, PillarName.distribution == Distribution.id),
            ]
        conditions = SQL('''
            PillarName.active = TRUE
            AND (PillarName.name = lower(%(text)s) OR

                 Product.fti @@ ftq(%(text)s) OR
                 lower(Product.title) = lower(%(text)s) OR

                 Project.fti @@ ftq(%(text)s) OR
                 lower(Project.title) = lower(%(text)s) OR

                 Distribution.fti @@ ftq(%(text)s) OR
                 lower(Distribution.title) = lower(%(text)s)
                )
            ''' % sqlvalues(text=ensure_unicode(text)))
        columns = [
            PillarName, OtherPillarName, Product, ProjectGroup, Distribution]
        for column in extra_columns:
            columns.append(column)
        return IStore(PillarName).using(*origin).find(
            tuple(columns), conditions)
예제 #30
0
 def __init__(self, session_data, product_id):
     self.session_data = session_data
     self.product_id = ensure_unicode(product_id)
     self.table_name = (
         session_data.session_data_container.session_pkg_data_table_name)
     self._populate()
예제 #31
0
 def __init__(self, session_data, product_id):
     self.session_data = session_data
     self.product_id = ensure_unicode(product_id)
     self.table_name = (
         session_data.session_data_container.session_pkg_data_table_name)
     self._populate()
예제 #32
0
 def addSources(self, names):
     """See `IPackageset`."""
     if isinstance(names, basestring):
         names = [ensure_unicode(names)]
     clauses = (SourcePackageName, SourcePackageName.name.is_in(names))
     self._api_add_or_remove(clauses, self._addSourcePackageNames)
예제 #33
0
 def queryByName(self, name):
     return IStore(BinaryPackageName).find(
         BinaryPackageName, name=ensure_unicode(name)).one()
예제 #34
0
 def queryByName(self, name):
     return IStore(BinaryPackageName).find(BinaryPackageName,
                                           name=ensure_unicode(name)).one()
예제 #35
0
 def new(self, name):
     return BinaryPackageName(name=ensure_unicode(name))
예제 #36
0
 def new(self, name):
     return BinaryPackageName(name=ensure_unicode(name))