[Pkg-debile-commits] [debile-slave] 01/100: Initial import
Sylvestre Ledru
sylvestre at alioth.debian.org
Mon Aug 19 14:52:57 UTC 2013
This is an automated email from the git hooks/post-receive script.
sylvestre pushed a commit to branch master
in repository debile-slave.
commit e1c82d07efa3c2dc9ed82706b2b2b6cb9567bdf3
Author: Paul Tagliamonte <tag at pault.ag>
Date: Tue May 21 23:57:32 2013 -0400
Initial import
---
.gitignore | 3 ++
ethel/__init__.py | 4 +++
ethel/chroot.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++
ethel/cli.py | 14 +++++++++
ethel/client.py | 34 ++++++++++++++++++++++
ethel/config.py | 12 ++++++++
ethel/utils.py | 33 +++++++++++++++++++++
setup.py | 28 ++++++++++++++++++
8 files changed, 211 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..34717c6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*pyc
+*swp
+*ethel*egg*
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/ethel/__init__.py b/ethel/__init__.py
new file mode 100644
index 0000000..4aa77f9
--- /dev/null
+++ b/ethel/__init__.py
@@ -0,0 +1,4 @@
+
+
+__appname__ = "ethel"
+__version__ = "0.0.1"
diff --git a/ethel/chroot.py b/ethel/chroot.py
new file mode 100644
index 0000000..2fabca1
--- /dev/null
+++ b/ethel/chroot.py
@@ -0,0 +1,83 @@
+from ethel.utils import run_command
+import configparser
+import contextlib
+import shutil
+import sys
+import os
+
+
+def get_mount_point(session):
+ cfg = configparser.ConfigParser()
+ fil = '/var/lib/schroot/session/%s' % (session)
+ if cfg.read(fil) == []:
+ raise KeyError("No such session: `%s' - %s" % (session, fil))
+ obj = cfg[session]
+ return obj['mount-location']
+
+
+def safe_run(cmd, expected=0):
+ out, err, ret = run_command(cmd)
+ if ret != expected:
+ print(cmd)
+ print(out.decode('utf-8'))
+ print(err.decode('utf-8'))
+ print(ret)
+
+ raise Exception("Bad command")
+ return out, err
+
+
+def scmd(session, command, expected=0, user=None):
+ cmds = ['schroot', '-r', '-c', session]
+ if user:
+ cmds += ['-u', user]
+ cmds += ['--'] + command
+ return safe_run(cmds, expected=expected)
+
+
+ at contextlib.contextmanager
+def schroot(chroot):
+ session = "ethel-%s" % (os.getpid())
+ out, err = safe_run(['schroot', '-b', '-n', session, '-c', chroot])
+ session = out.strip().decode('utf-8')
+
+ try:
+ print("[ethel] Started session: %s" % (session))
+ yield session
+ finally:
+ out, err = safe_run(['schroot', '-e', '-c', session])
+
+
+def copy(session, source, dest):
+ root = get_mount_point(session)
+ dest = os.path.join(root, dest)
+ return shutil.copy2(source, dest)
+
+
+def adequate(chroot, package):
+ with schroot(chroot) as session:
+ deb = os.path.basename(package)
+ if not deb.endswith('.deb'):
+ raise ValueError("Stop with the crack smoking")
+
+ where = '/tmp/%s' % (deb)
+ copy(session, package, where)
+
+ out, err = scmd(session, [
+ 'apt-get', 'install', '-y', 'adequate'
+ ], user='root')
+
+ out, err = scmd(session, [
+ 'dpkg', '-i', where
+ ], user='root', expected=1)
+
+ out, err = scmd(session, [
+ 'apt-get', 'install', '-y', '-f'
+ ], user='root')
+
+ out, err = scmd(session, ['adequate', deb.split("_", 1)[0]])
+ print(out, err)
+
+
+adequate('unstable-amd64',
+ '/home/tag/dev/debian/fluxbox/fluxbox_1.3.5-1_amd64.deb')
diff --git a/ethel/cli.py b/ethel/cli.py
new file mode 100644
index 0000000..f2ed4ab
--- /dev/null
+++ b/ethel/cli.py
@@ -0,0 +1,14 @@
+from ethel.client import submit_report, next_job, close_job
+import sys
+
+
+def submit():
+ return submit_report(sys.argv[1], sys.argv[2])
+
+
+def next():
+ return next_job(sys.argv[1])
+
+
+def close():
+ return close(sys.argv[1])
diff --git a/ethel/client.py b/ethel/client.py
new file mode 100644
index 0000000..8194c08
--- /dev/null
+++ b/ethel/client.py
@@ -0,0 +1,34 @@
+from ethel.config import load
+
+from storz.decompress import digest_firehose_tree
+from firehose.model import Analysis
+import xmlrpc.client
+
+
+def get_proxy():
+ info = load()
+ proxy = xmlrpc.client.ServerProxy(
+ "http://{user}:{password}@{host}:{port}/".format(
+ user=info['user'],
+ password=info['password'],
+ host=info['host'],
+ port=info['port']
+ ), allow_none=True)
+ return proxy
+
+
+def submit_report(report, job):
+ proxy = get_proxy()
+ report = Analysis.from_xml(report)
+ obj = proxy.submit_report(job, digest_firehose_tree(report))
+ return obj
+
+
+def next_job(job):
+ proxy = get_proxy()
+ return proxy.get_next_job(job)
+
+
+def close_job(job):
+ proxy = get_proxy()
+ return proxy.close_job(job)
diff --git a/ethel/config.py b/ethel/config.py
new file mode 100644
index 0000000..1fac506
--- /dev/null
+++ b/ethel/config.py
@@ -0,0 +1,12 @@
+import configparser
+
+CONFIG_BLOCK = "host"
+
+
+def load(location="/etc/ethel.ini", block="host"):
+ if block is None:
+ block = CONFIG_BLOCK
+
+ cfg = configparser.ConfigParser()
+ cfg.read(location)
+ return cfg[block]
diff --git a/ethel/utils.py b/ethel/utils.py
new file mode 100644
index 0000000..e74426f
--- /dev/null
+++ b/ethel/utils.py
@@ -0,0 +1,33 @@
+from contextlib import contextmanager
+import subprocess
+import tempfile
+import shlex
+import os
+
+
+ at contextmanager
+def tfile():
+ _, fp = tempfile.mkstemp()
+ try:
+ yield fp
+ finally:
+ os.unlink(fp)
+
+
+def run_command(command, stdin=None):
+ if not isinstance(command, list):
+ command = shlex.split(command)
+ try:
+ pipe = subprocess.Popen(command, shell=False,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ except OSError:
+ return (None, None, -1)
+
+ kwargs = {}
+ if stdin:
+ kwargs['input'] = stdin.read()
+
+ (output, stderr) = pipe.communicate(**kwargs)
+ return (output, stderr, pipe.returncode)
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..903a98a
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,28 @@
+from ethel import __appname__, __version__
+from setuptools import setup
+
+
+long_description = ""
+
+setup(
+ name=__appname__,
+ version=__version__,
+ scripts=[],
+ packages=[
+ 'ethel',
+ ],
+ author="Paul Tagliamonte",
+ author_email="tag at pault.ag",
+ long_description=long_description,
+ description='Ethyl!',
+ license="Expat",
+ url="http://deb.io/",
+ platforms=['any'],
+ entry_points = {
+ 'console_scripts': [
+ 'ethel-submit = ethel.cli:submit',
+ 'ethel-next = ethel.cli:next',
+ 'ethel-close = ethel.cli:close',
+ ],
+ }
+)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-debile/debile-slave.git
More information about the Pkg-debile-commits
mailing list