import logging
-from . import arches
from . import base
from . import builds
from . import packages
from . import sources
-from . import updates
from .repository import Repository, RepositoryAux
+from .decorators import *
+
class Distributions(base.Object):
- def get_all(self):
- distros = self.db.query("SELECT * FROM distributions ORDER BY name")
+ def _get_distribution(self, query, *args):
+ res = self.db.get(query, *args)
+
+ if res:
+ return Distribution(self.backend, res.id, data=res)
- return [Distribution(self.pakfire, d.id, d) for d in distros]
+ def _get_distributions(self, query, *args):
+ res = self.db.query(query, *args)
- def get_by_id(self, id):
- distro = self.db.get("SELECT * FROM distributions WHERE id = %s LIMIT 1", id)
+ for row in res:
+ yield Distribution(self.backend, row.id, data=row)
- if distro:
- return Distribution(self.pakfire, distro.id, distro)
+ def __iter__(self):
+ distros = self._get_distributions("SELECT * FROM distributions \
+ WHERE deleted IS FALSE ORDER BY name")
- def get_by_name(self, name):
- distro = self.db.get("SELECT * FROM distributions WHERE sname = %s LIMIT 1", name)
+ return iter(distros)
- if distro:
- return Distribution(self.pakfire, distro.id, distro)
+ def get_by_id(self, distro_id):
+ return self._get_distribution("SELECT * FROM distributions \
+ WHERE id = %s", distro_id)
+
+ def get_by_name(self, sname):
+ return self._get_distribution("SELECT * FROM distributions \
+ WHERE sname = %s AND deleted IS FALSE", sname)
def get_by_ident(self, ident):
return self.get_by_name(ident)
return self.get_by_ident("ipfire3")
-class Distribution(base.Object):
- def __init__(self, pakfire, id, data=None):
- base.Object.__init__(self, pakfire)
- self.id = id
-
- self._data = data
- self._arches = None
- self._sources = None
+class Distribution(base.DataObject):
+ table = "distributions"
def __repr__(self):
return "<%s %s>" % (self.__class__.__name__, self.name)
- @property
- def data(self):
- if self._data is None:
- self._data = self.db.get("SELECT * FROM distributions WHERE id = %s", self.id)
-
- return self._data
-
- def set(self, key, value):
- self.db.execute("UPDATE distributions SET %s = %%s WHERE id = %%s" % key,
- value, self.id)
-
- if self._data:
- self._data[key] = value
-
@property
def info(self):
return {
return self.data.slogan
def get_arches(self):
- if self._arches is None:
- _arches = self.db.query("SELECT arch_id AS id FROM distro_arches \
- WHERE distro_id = %s", self.id)
-
- self._arches = []
- for arch in _arches:
- arch = arches.Arch(self.pakfire, arch.id)
- self._arches.append(arch)
-
- # Sort architectures by their priority.
- self._arches.sort()
+ res = self.db.query("SELECT arch FROM distributions_arches \
+ WHERE distro_id = %s ORDER BY arch", self.id)
- return self._arches
+ return sorted((row.arch for row in res))
- def set_arches(self, _arches):
+ def set_arches(self, arches):
self.db.execute("DELETE FROM distro_arches WHERE distro_id = %s", self.id)
- for arch in _arches:
- self.db.execute("INSERT INTO distro_arches(distro_id, arch_id) \
- VALUES(%s, %s)", self.id, arch.id)
+ for arch in arches:
+ self.db.execute("INSERT INTO distro_arches(distro_id, arch) \
+ VALUES(%s, %s)", self.id, arch)
- self._arches = _arches
+ self.arches = sorted(arches)
- arches = property(get_arches, set_arches)
+ arches = lazy_property(get_arches, set_arches)
@property
def vendor(self):
return self.data.contact
def set_contact(self, contact):
- self.db.execute("UPDATE distributions SET contact = %s WHERE id = %s",
- contact, self.id)
-
- if self._data:
- self._data["contact"] = contact
+ self._set_attribute("contact", contact)
contact = property(get_contact, set_contact)
return self.data.tag
def set_tag(self, tag):
- self.db.execute("UPDATE distributions SET tag = %s WHERE id = %s",
- tag, self.id)
-
- if self._data:
- self._data["tag"] = tag
+ self._set_attribute("tag", tag)
tag = property(get_tag, set_tag)
def description(self):
return self.data.description or ""
- @property
+ @lazy_property
def repositories(self):
- _repos = self.db.query("SELECT id FROM repositories WHERE distro_id = %s", self.id)
+ _repositories = self.backend.repos._get_repositories("SELECT * FROM repositories \
+ WHERE distro_id = %s", self.id)
- repos = []
- for repo in _repos:
- repo = Repository(self.pakfire, repo.id)
- repo._distro = self
+ # Cache
+ repositories = []
+ for repo in _repositories:
+ repo.distro = self
+ repositories.append(repo)
- repos.append(repo)
+ return sorted(repositories)
- return sorted(repos)
-
- @property
+ @lazy_property
def repositories_aux(self):
_repos = self.db.query("SELECT id FROM repositories_aux \
WHERE status = 'enabled' AND distro_id = %s", self.id)
return sorted(repos)
def get_repo(self, name):
- repo = self.db.get("SELECT id FROM repositories WHERE distro_id = %s AND name = %s",
- self.id, name)
+ repo = self.backend.repos._get_repository("SELECT * FROM repositories \
+ WHERE distro_id = %s AND name = %s", self.id, name)
- if not repo:
- return
-
- repo = Repository(self.pakfire, repo.id)
- repo._distro = self
+ # Cache
+ repo.distro = self
return repo
if repos:
return self.repositories[-1]
- @property
- def comprehensive_repositories(self):
- return [r for r in self.repositories if r.comprehensive]
-
- def add_repository(self, name, description):
- return Repository.new(self.pakfire, self, name, description)
-
@property
def log(self):
return [] # TODO
def delete_package(self, name):
pass # XXX figure out what to do at this place
- @property
+ @lazy_property
def sources(self):
- if self._sources is None:
- self._sources = []
-
- for source in self.db.query("SELECT id FROM sources WHERE distro_id = %s", self.id):
- source = sources.Source(self.pakfire, source.id)
- self._sources.append(source)
+ _sources = []
- self._sources.sort()
+ for source in self.db.query("SELECT id FROM sources WHERE distro_id = %s", self.id):
+ source = sources.Source(self.pakfire, source.id)
+ _sources.append(source)
- return self._sources
+ return sorted(_sources)
- def get_source(self, ident):
+ def get_source(self, identifier):
for source in self.sources:
- if not source.identifier == ident:
+ if not source.identifier == identifier:
continue
return source
from . import base
from . import logs
+from .decorators import *
+
class Repositories(base.Object):
- def get_all(self):
- repos = self.db.query("SELECT * FROM repositories")
+ def _get_repository(self, query, *args):
+ res = self.db.get(query, *args)
- return [Repository(self.pakfire, r.id, r) for r in repos]
+ if res:
+ return Repository(self.backend, res.id, data=res)
- def get_by_id(self, repo_id):
- repo = self.db.get("SELECT * FROM repositories WHERE id = %s", repo_id)
+ def _get_repositories(self, query, *args):
+ res = self.db.query(query, *args)
+
+ for row in res:
+ yield Repository(self.backend, row.id, data=row)
+
+ def __iter__(self):
+ repositories = self._get_repositories("SELECT * FROM repositories \
+ ORDER BY distro_id, name")
- if repo:
- return Repository(self.pakfire, repo.id, repo)
+ return iter(repositories)
+
+ def get_by_id(self, repo_id):
+ return self._get_repository("SELECT * FROM repositories \
+ WHERE id = %s", repo_id)
def get_needs_update(self, limit=None):
query = "SELECT id FROM repositories WHERE needs_update = 'Y'"
return cls(pakfire, id)
- @property
+ @lazy_property
def distro(self):
- if self._distro is None:
- self._distro = self.pakfire.distros.get_by_id(self.data.distro_id)
- assert self._distro
-
- return self._distro
+ return self.backend.distros.get_by_id(self.data.distro_id)
@property
def info(self):
return self.pakfire.repos.get_history(**kwargs)
def get_build_times(self):
- noarch = self.pakfire.arches.get_by_name("noarch")
- assert noarch
-
times = []
- for arch in self.pakfire.arches.get_all():
- time = self.db.get("SELECT SUM(UNIX_TIMESTAMP(jobs.time_finished) - UNIX_TIMESTAMP(jobs.time_started)) AS time FROM jobs \
+ for arch in self.arches:
+ time = self.db.get("SELECT SUM(jobs.time_finished - jobs.time_started) AS time FROM jobs \
JOIN builds ON builds.id = jobs.build_id \
JOIN repositories_builds ON builds.id = repositories_builds.build_id \
- WHERE (jobs.arch_id = %s OR jobs.arch_id = %s) AND \
+ WHERE (jobs.arch = %s OR jobs.arch = %s) AND \
jobs.type = 'build' AND \
- repositories_builds.repo_id = %s", arch.id, noarch.id, self.id)
+ repositories_builds.repo_id = %s", arch, "noarch", self.id)
- times.append((arch, time.time))
+ times.append((arch, time.time.total_seconds()))
return times
description text,
vendor text NOT NULL,
contact text,
- tag text NOT NULL
+ tag text NOT NULL,
+ deleted boolean DEFAULT false NOT NULL
);
ALTER TABLE distributions OWNER TO pakfire;
+--
+-- Name: distributions_arches; Type: TABLE; Schema: public; Owner: pakfire; Tablespace:
+--
+
+CREATE TABLE distributions_arches (
+ id integer NOT NULL,
+ distro_id integer NOT NULL,
+ arch text NOT NULL
+);
+
+
+ALTER TABLE distributions_arches OWNER TO pakfire;
+
--
-- Name: distributions_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
--
ALTER SEQUENCE distributions_id_seq OWNED BY distributions.id;
---
--- Name: distro_arches; Type: TABLE; Schema: public; Owner: pakfire; Tablespace:
---
-
-CREATE TABLE distro_arches (
- id integer NOT NULL,
- distro_id integer NOT NULL,
- arch_id integer NOT NULL
-);
-
-
-ALTER TABLE distro_arches OWNER TO pakfire;
-
--
-- Name: distro_arches_id_seq; Type: SEQUENCE; Schema: public; Owner: pakfire
--
-- Name: distro_arches_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: pakfire
--
-ALTER SEQUENCE distro_arches_id_seq OWNED BY distro_arches.id;
+ALTER SEQUENCE distro_arches_id_seq OWNED BY distributions_arches.id;
--
time_min integer DEFAULT 0 NOT NULL,
time_max integer DEFAULT 0 NOT NULL,
update_started timestamp without time zone,
- update_ended timestamp without time zone
+ update_ended timestamp without time zone,
+ deleted boolean DEFAULT false NOT NULL
);
-- Name: id; Type: DEFAULT; Schema: public; Owner: pakfire
--
-ALTER TABLE ONLY distro_arches ALTER COLUMN id SET DEFAULT nextval('distro_arches_id_seq'::regclass);
+ALTER TABLE ONLY distributions_arches ALTER COLUMN id SET DEFAULT nextval('distro_arches_id_seq'::regclass);
--
-- Name: idx_2198048_primary; Type: CONSTRAINT; Schema: public; Owner: pakfire; Tablespace:
--
-ALTER TABLE ONLY distro_arches
+ALTER TABLE ONLY distributions_arches
ADD CONSTRAINT idx_2198048_primary PRIMARY KEY (id);
CREATE INDEX builds_watchers_build_id ON builds_watchers USING btree (build_id);
+--
+-- Name: distributions_arches_distro_id; Type: INDEX; Schema: public; Owner: pakfire; Tablespace:
+--
+
+CREATE INDEX distributions_arches_distro_id ON distributions_arches USING btree (distro_id);
+
+
+--
+-- Name: distributions_sname; Type: INDEX; Schema: public; Owner: pakfire; Tablespace:
+--
+
+CREATE UNIQUE INDEX distributions_sname ON distributions USING btree (sname) WHERE (deleted IS FALSE);
+
+
--
-- Name: filelists_name; Type: INDEX; Schema: public; Owner: pakfire; Tablespace:
--
--
--- Name: distro_arches_arch_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
+-- Name: distributions_arches_arch; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
--
-ALTER TABLE ONLY distro_arches
- ADD CONSTRAINT distro_arches_arch_id FOREIGN KEY (arch_id) REFERENCES arches(id);
+ALTER TABLE ONLY distributions_arches
+ ADD CONSTRAINT distributions_arches_arch FOREIGN KEY (arch) REFERENCES arches(name);
--
-- Name: distro_arches_distro_id; Type: FK CONSTRAINT; Schema: public; Owner: pakfire
--
-ALTER TABLE ONLY distro_arches
+ALTER TABLE ONLY distributions_arches
ADD CONSTRAINT distro_arches_distro_id FOREIGN KEY (distro_id) REFERENCES distributions(id);