Example #1
0
 def __init__(self, path):
     # check locality
     if not istools.isfile(path):
         raise ISError("Database must be local")
     self.path = os.path.abspath(path)
     if not os.path.exists(self.path):
         raise ISError("Database not exists")
     self.conn = sqlite3.connect(self.path, isolation_level=None)
     self.conn.execute("PRAGMA foreign_keys = ON")
     # get database version
     try:
         r = self.ask("SELECT version FROM repository").fetchone()
         if r is None:
             raise TypeError()
         self.version = float(r[0])
     except:
         self.version = 1.0
     if math.floor(self.version) >= math.floor(Database.version) + 1.0:
         raise ISWarning(u"New database format (%s), please upgrade "
                         "your Installsystems version" % self.version)
     # we make a query to be sure format is valid
     try:
         self.ask("SELECT * FROM image")
     except:
         debug(u"Invalid database format: %s" % self.version)
         raise ISError("Invalid database format")
Example #2
0
 def register(self, config, temp=False, nosync=False, offline=False):
     '''
     Register a repository from its config
     temp: repository is stored in a temporary location
     nosync: register repository as online, but no sync is done before
     offline: repository is marked offline
     '''
     # check filter on name
     if len(self.filter) > 0:
         if config.name not in self.filter:
             debug(u"Filtering repository %s" % config.name)
             return
     # repository is offline
     if config.offline or offline:
         debug(u"Registering offline repository %s (%s)" % (config.path, config.name))
         # we must force offline in cast of argument offline
         config.offline = True
         self.repos.append(self.factory.create(config))
     # if path is local, no needs to create a cache
     elif istools.isfile(config.path):
         debug(u"Registering direct repository %s (%s)" % (config.path, config.name))
         self.repos.append(self.factory.create(config))
     # path is remote, we need to create a cache
     else:
         debug(u"Registering cached repository %s (%s)" % (config.path, config.name))
         self.repos.append(self._cachify(config, temp, nosync))
Example #3
0
 def dbpath(self, value):
     '''
     Set db path
     '''
     # dbpath must be local, sqlite3 requirement
     if not istools.isfile(value):
         raise ValueError("Database path must be local")
     self._dbpath = os.path.abspath(value)
Example #4
0
 def create(cls, path):
     arrow("Creating repository database")
     # check locality
     if not istools.isfile(path):
         raise ISError("Database creation must be local")
     path = os.path.abspath(path)
     if os.path.exists(path):
         raise ISError("Database already exists. Remove it before")
     try:
         conn = sqlite3.connect(path, isolation_level=None)
         conn.execute("PRAGMA foreign_keys = ON")
         conn.executescript(istemplate.createdb)
         conn.execute("INSERT INTO repository values (?,?,?)",
                      (str(uuid.uuid4()), Database.version, "",))
         conn.commit()
         conn.close()
     except Exception as e:
         raise ISError(u"Create database failed", e)
     return cls(path)
Example #5
0
 def __init__(self, path):
     '''
     Initialize source image
     '''
     Image.__init__(self)
     # check local repository
     if not isfile(path):
         raise NotImplementedError("SourceImage must be local")
     self.base_path = abspath(path)
     for pathtype in ("build", "parser", "setup", "payload", "lib"):
         setattr(self, u"%s_path" % pathtype, join(self.base_path, pathtype))
     self.check_source_image()
     self.description = self.parse_description()
     self.changelog = self.parse_changelog()
     self.modules = {}
     # script tarball path
     self.image_name = u"%s-%s%s" % (self.description["name"],
                                     self.description["version"],
                                     self.extension)
Example #6
0
 def __init__(self, cache_path=None, timeout=None, filter=None, search=None):
     self.repos = []
     self.tempfiles = []
     self.filter = [] if filter is None else filter
     self.search = [] if search is None else search
     self.timeout = timeout or 3
     self.factory = RepositoryFactory()
     debug(u"Repository timeout setted to %ds" % self.timeout)
     if cache_path is None:
         self.cache_path = None
         debug("No repository cache")
     else:
         if not istools.isfile(cache_path):
             raise NotImplementedError("Repository cache must be local")
         self.cache_path =  os.path.abspath(cache_path)
         # must_path is a list of directory which must exists
         # create directory if not exists
         if not os.path.exists(self.cache_path):
             os.mkdir(self.cache_path)
         # ensure directories are avaiblable
         if not os.access(self.cache_path, os.W_OK | os.X_OK):
             raise ISError(u"%s is not writable or executable" % self.cache_path)
         debug(u"Repository cache is in %s" % self.cache_path)
Example #7
0
 def create(cls, path, force=False):
     '''
     Create an empty source image
     '''
     # check local repository
     if not isfile(path):
         raise NotImplementedError("SourceImage must be local")
     # main path
     build_path = join(path, "build")
     parser_path = join(path, "parser")
     setup_path = join(path, "setup")
     payload_path = join(path, "payload")
     lib_path = join(path, "lib")
     # create base directories
     arrow("Creating base directories")
     try:
         for d in (path, build_path, parser_path, setup_path, payload_path,
                   lib_path):
             if not exists(d) or not isdir(d):
                 mkdir(d)
     except Exception as e:
         raise ISError(u"Unable to create directory: %s" % d, e)
     # create example files
     arrow("Creating examples")
     arrowlevel(1)
     # create dict of file to create
     examples = {}
     # create description example from template
     examples["description"] = {
         "path": "description",
         "content": DESCRIPTION_TPL % {
             "name": "",
             "version": "1",
             "description": "",
             "author": "",
             "is_min_version": VERSION,
             "compressor": "gzip = *\nnone = *.gz, *.bz2, *.xz"}
     }
     # create changelog example from template
     examples["changelog"] = {"path": "changelog", "content": CHANGELOG_TPL}
     # create build example from template
     examples["build"] = {"path": "build/01-build.py", "content": BUILD_TPL}
     # create parser example from template
     examples["parser"] = {"path": "parser/01-parser.py", "content": PARSER_TPL}
     # create setup example from template
     examples["setup"] = {"path": "setup/01-setup.py", "content": SETUP_TPL}
     for name in examples:
         try:
             arrow(u"Creating %s example" % name)
             expath = join(path, examples[name]["path"])
             if not force and exists(expath):
                 warn(u"%s already exists. Skipping!" % expath)
                 continue
             open(expath, "w").write(examples[name]["content"])
         except Exception as e:
             raise ISError(u"Unable to create example file", e)
     try:
         # setting executable rights on files in setup and parser
         arrow("Setting executable rights on scripts")
         oldmask = umask(0)
         umask(oldmask)
         for dpath in (build_path, parser_path, setup_path):
             for f in listdir(dpath):
                 chrights(join(dpath, f), mode=0777 & ~oldmask)
     except Exception as e:
         raise ISError(u"Unable to set rights", e)
     arrowlevel(-1)
Example #8
0
 def __init__(self, config, db=None):
     self.config = config
     self.local = istools.isfile(self.config.path)
     self.db = db