Commits

Nekmo  committed f0760ef

Primera edición

  • Participants

Comments (0)

Files changed (13)

+[Dolphin]
+Timestamp=2012,9,13,23,14,52
+
+[Settings]
+HiddenFilesShown=true
+# use glob syntax.
+syntax: glob
+
+*.pyc
+*~
+*kate-swp

File library/__init__.py

+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+from functools import wraps
+import ConfigParser as configparser
+import db
+import os
+
+class Base(object):
+    def __init__(self, dbfile, configfile):
+        self.config = configparser.ConfigParser()
+        self.config.read(configfile)
+        self.dbfile = dbfile
+    
+    def load_db(mode):
+        def fnct(f):
+            @wraps(f)
+            def f2(f_, *args, **kwargs):
+                self = args[0]
+                self.db = db.SQLite(self.dbfile)
+                return f(f_, *args, **kwargs)
+            return f2
+        return fnct
+    
+    def _sync_repo(self, section, server):
+        self.db.
+    
+    @load_db
+    def sync(self, force=False):
+        for section in self.config.sections():
+            if section in ['master']: continue
+            if 'Server' in self.config.options(section):
+                server = self.config.get(section, 'Server')
+            self._sync_repo(section, server)
+        
+    
+if __name__ == '__main__':
+    config = configparser.ConfigParser()
+    config.read('options.cfg')
+    db_file = config.get('options', 'db_file')
+    configfile = config.get('options', 'configfile')
+    if not os.path.exists(db_file):
+        db.create_db(db_file)
+    base = Base()

File library/conf.d/mirrorlist

+ 

File library/conf.d/upm.conf

+[options]
+
+[master]
+Server=http://localhost:8000/latest
+
+[extra]
+Server=http://localhost:8000/latest

File library/db.py

+import sqlite3
+
+        
+class SQLite(object):
+    def __init__(self, dbfile):
+        self.dbfile = dbfile
+        self.conn = sqlite3.connect(dbfile)
+        self.c = self.conn.cursor()
+        
+    def execute(self, code, *args, **kwargs):
+        return self.c.execute(code, *args, **kwargs)
+        
+    def executescript(self, code, *args, **kwargs):
+        return self.c.executescript(code, *args, **kwargs)
+        
+    def commit(self, *args, **args):
+        return self.c.commit(*args, **kwargs)
+        
+    def clsoe(self, *args, **args):
+        return self.c.close(*args, **kwargs)
+        
+def create_db(file):
+    d = SQLite(file)
+    d.executescript(code)
+    d.commit()
+    d.close()

File library/models.sql

+CREATE TABLE branch (
+    id INTEGER NOT NULL PRIMARY KEY,
+    name TEXT NOT NULL,
+    last_update INTEGER,
+    change_date INTEGER
+);
+
+CREATE TABLE checksum_method (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL
+);
+
+CREATE TABLE operating_system (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL
+);
+
+CREATE TABLE architecture (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL
+);
+
+CREATE TABLE arch (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    operating_system INTEGER, /* Véase operating_system */
+    architecture INTEGER /* Véase architecture */
+);
+
+/* Paquetes locales */
+
+CREATE TABLE local_group (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT UNIQUE NOT NULL
+);
+
+CREATE TABLE local_package (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    branch INTEGER, /* Ver tabla branch */
+    creation_date INTEGER NOT NULL, /* Fecha de creación del paquete  */
+    revision REAL NOT NULL, /* Numeración de versiones/revisiones. <versión>.<revisión> */
+    version, TEXT NOT NULL,
+    install_datel INTEGER NOT NULL,
+    arch INTEGER, /* Véase arch */
+    checksum INTEGER,
+    checksum_method INTEGER, /* Véase checksum_method */
+    local_group INTEGER /* véase local_group */
+);
+
+CREATE TABLE local_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_dependence (
+  local_package_id  int NOT NULL,
+  local_dependence_id    int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_dependence_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_dependence_relation_ibfk_2
+    FOREIGN KEY (local_dependence_id)
+    REFERENCES local_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE local_conflict (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_conflict (
+  local_package_id  int NOT NULL,
+  local_conflict_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_conflict_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_conflict_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_conflict_relation_ibfk_2
+    FOREIGN KEY (local_conflict_id)
+    REFERENCES local_conflict(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE local_replace (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_replace (
+  local_package_id  int NOT NULL,
+  local_replace_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_replace_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_replace_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_replace_relation_ibfk_2
+    FOREIGN KEY (local_replace_id)
+    REFERENCES local_replace(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE local_make_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_make_dependence (
+  local_package_id  int NOT NULL,
+  local_make_dependence_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_make_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_make_dependence_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_make_dependence_relation_ibfk_2
+    FOREIGN KEY (local_make_dependence_id)
+    REFERENCES local_make_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE local_opt_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_opt_dependence (
+  local_package_id  int NOT NULL,
+  local_opt_dependence_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_opt_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_opt_dependence_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_opt_dependence_relation_ibfk_2
+    FOREIGN KEY (local_opt_dependence_id)
+    REFERENCES local_opt_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE local_provide (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE local_package_local_provide (
+  local_package_id  int NOT NULL,
+  local_provide_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (local_package_id, local_provide_id),
+  /* Foreign keys */
+  CONSTRAINT local_package_local_provide_relation_ibfk_1
+    FOREIGN KEY (local_package_id)
+    REFERENCES local_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT local_package_local_provide_relation_ibfk_2
+    FOREIGN KEY (local_provide_id)
+    REFERENCES local_provide(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+/* Paquetes servidor */
+CREATE TABLE repo_group (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT UNIQUE NOT NULL
+);
+
+CREATE TABLE repo_package (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    branch INTEGER,
+    creation_date INTEGER NOT NULL, /* Fecha de creación del paquete  */
+    revision REAL NOT NULL, /* Numeración de versiones/revisiones. <versión>.<revisión> */
+    version TEXT NOT NULL,
+    install_date INTEGER NOT NULL,
+    arch INTEGER, /* Véase arch */
+    checksum INTEGER,
+    checksum_method INTEGER, /* Véase checksum_method */
+    repo_group INTEGER /* véase repo_group */
+);
+
+CREATE TABLE repo_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_dependence (
+  repo_package_id  int NOT NULL,
+  repo_dependence_id    int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_dependence_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_dependence_relation_ibfk_2
+    FOREIGN KEY (repo_dependence_id)
+    REFERENCES repo_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE repo_conflict (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_conflict (
+  repo_package_id  int NOT NULL,
+  repo_conflict_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_conflict_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_conflict_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_conflict_relation_ibfk_2
+    FOREIGN KEY (repo_conflict_id)
+    REFERENCES repo_conflict(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE repo_replace (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_replace (
+  repo_package_id  int NOT NULL,
+  repo_replace_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_replace_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_replace_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_replace_relation_ibfk_2
+    FOREIGN KEY (repo_replace_id)
+    REFERENCES repo_replace(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE repo_make_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_make_dependence (
+  repo_package_id  int NOT NULL,
+  repo_make_dependence_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_make_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_make_dependence_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_make_dependence_relation_ibfk_2
+    FOREIGN KEY (repo_make_dependence_id)
+    REFERENCES repo_make_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE repo_opt_dependence (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_opt_dependence (
+  repo_package_id  int NOT NULL,
+  repo_opt_dependence_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_opt_dependence_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_opt_dependence_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_opt_dependence_relation_ibfk_2
+    FOREIGN KEY (repo_opt_dependence_id)
+    REFERENCES repo_opt_dependence(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);
+
+CREATE TABLE repo_provide (
+    id INTEGER PRIMARY KEY NOT NULL,
+    name TEXT NOT NULL,
+    min_version TEXT,
+    max_version TEXT,
+    max_revision REAL,
+    min_revision REAL
+);
+
+/* Many to Many */
+CREATE TABLE repo_package_repo_provide (
+  repo_package_id  int NOT NULL,
+  repo_provide_id  int NOT NULL,
+  /* Keys */
+  PRIMARY KEY (repo_package_id, repo_provide_id),
+  /* Foreign keys */
+  CONSTRAINT repo_package_repo_provide_relation_ibfk_1
+    FOREIGN KEY (repo_package_id)
+    REFERENCES repo_package(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT, 
+  CONSTRAINT repo_package_repo_provide_relation_ibfk_2
+    FOREIGN KEY (repo_provide_id)
+    REFERENCES repo_provide(id)
+    ON DELETE RESTRICT
+    ON UPDATE RESTRICT
+);

File library/options.cfg

+[config]
+db_file = db.sqlite
+config_file = conf.d/upm.conf

File library/parser.py

+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+import sys
+from pyparsing import alphas, alphanums, nums, ZeroOrMore, Word, Group, Suppress, Combine, quotedString
+
+LEVELS = ['#', '=']
+
+class Section(list):
+    def __init__(self, name):
+        list.__init__(self)
+        self.name = name
+        self.defs = {}
+        self.elems = []
+        
+
+class Parser(object):
+    def __init__(self):
+        self.sections = {}
+        self.levels_sections = []
+        
+        def_ = Group(Combine(Word(alphanums) + Suppress(": ")) + Word(quotedString))
+        self.record = def_
+    
+    def feedfile(self, fp):
+        lines = fp.readlines()
+        i = 0
+        for line in lines:
+            if lines[i + 1] and lines[i + 1][0] in LEVELS:
+                # Es una sección
+                for level in LEVELS:
+                    if not level == lines[i + 1][0]: continue
+                    index = LEVELS.index(level)
+                    if index < len(self.levels_sections) - 1:
+                        # Se cierran los niveles anteriores del árbol
+                        self.levels_sections = self.levels_sections[0:index]
+                    section = Section(line)
+                    if self.levels_sections:
+                        self.levels_sections[-1].append(section)
+                    self.levels_sections.append(section)
+            else:
+                try:
+                    res = self.record.parseString(line)
+                except:
+                    res = ''
+                print(res)
+            i += 1
+
+if __name__ == '__main__':
+    parser = Parser()
+    parser.feedfile(open(sys.argv[1]))

File library/test/INSTALL

+About
+#####
+Name: "python-lxml"
+Ver: "2.3-1"
+Arch: "x86" "x86_64"
+Author: "Nicolas Tesla" "Steven Murphy"
+Website: "http://lxml.de"
+Description: "Python binding for the libxml2 and libxslt libraries"
+License: "BSD" "MIT"
+Packager: "Smith Williams <swilliams@server>"
+
+Conflicts
+#########
+    - python-lxml-bad >= 2.1.0
+    
+for "Debian" ver >= "6.0":
+    - python-lxml-very-bad
+
+Dependencies
+############
+    - python
+    - libxslt
+
+Install
+#######
+Alert
+=====
+Un mensaje de aviso
+
+1. Pre-install
+==============
+for "Archlinux" run in "shell":
+    $ cd ...
+    $ rm ...
+    $ <more commands>
+
+2. Build
+========
+    $ cd ...
+    $ cmake ...
+    
+3. Package
+==========
+    # make ...
+    # install ...
+    
+4. Post-install
+===============
+    ...
+    
+Upgrade
+#######
+...
+
+Remove
+######

File library/test/repo/latest

+/home/nekmo/Projects/universal-package-manager/library/test/repo/dates/2012/09/15

File main.py

Empty file added.

File self_extract.sh

+#!/usr/bin/env bash
+# UPM v0.1
+BS=2048
+UPM=http://...
+
+if which upm > /dev/null; then
+    upm -i "${BASH_SOURCE[0]}"
+    exit 0
+fi
+
+detect_show_method(){
+    if which kdialog > /dev/null; then
+        show_mehod='kdialog'
+    elif which zenity > /dev/null; then
+        show_mehod='zenity'
+    else
+        show_mehod='cli'
+    fi
+}
+if [ ! $show_mehod ]; then
+    detect_show_method
+fi
+
+msgyesno(){
+    if [ "$show_mehod" == 'kdialog' ]; then
+        kdialog --title="$2" --yesno "$1"
+        echo "$?"
+    elif [ "$show_mehod" == 'kdialog' ]; then
+        zenity --question --title="$2" --text "$1"
+        echo "$?"
+    else
+        while true; do
+            echo "$1"  1>&2
+            read -p "[y/n] " resp
+            resp=`echo $resp | tr '[:upper:]' '[:lower:]'`
+            if [[ ${resp[0]} != "y" && ${resp[0]} != "n" ]]; then
+                echo "[!!] Invalid response"  1>&2
+            else
+                if [[ ${resp[0]} == "y" ]]; then
+                    resp="0"
+                else
+                    resp="1"
+                fi
+                break
+            fi
+        done
+        if [ "$resp" == "0" ]; then
+            echo ""
+        else
+            echo "1"
+        fi
+    fi
+}
+
+resp=$(msgyesno "Do yoy want to install a package manager to install this package easily?" "Install Universal Package Manager")
+
+if [ $resp == "1" ]; then
+    tofile="/tmp/"`date +%s`.sh
+    wget $UPM_URL -O $tofile
+    bash $tofile
+else
+    datasize=`stat -c%s "${BASH_SOURCE[0]}"` - $BS
+    tail -c $datasize | tar xjv
+fi