[Pkg-debile-commits] [debile-slave] 04/100: adding abort script

Sylvestre Ledru sylvestre at alioth.debian.org
Mon Aug 19 14:52:58 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 e3f16e5bca45d0342b2932d010fd44294d1307fb
Author: Paul Tagliamonte <tag at pault.ag>
Date:   Wed May 22 13:14:25 2013 -0400

    adding abort script
---
 bin/schroot-abort-repack |   18 ++++++++++++++++++
 ethel/chroot.py          |   36 ++++++++++++++++++++++++++++++++----
 setup.py                 |    1 +
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/bin/schroot-abort-repack b/bin/schroot-abort-repack
new file mode 100755
index 0000000..40cd1fe
--- /dev/null
+++ b/bin/schroot-abort-repack
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+import configparser
+import sys
+
+if len(sys.argv) <= 1:
+    print("need a session id")
+    sys.exit(1)
+
+session = sys.argv[1]
+
+cfg = configparser.ConfigParser()
+path = "/var/lib/schroot/session/%s" % (session)
+if cfg.read(path) == []:
+    print("Need a valid session")
+    sys.exit(2)
+
+cfg[session]['file-repack'] = 'false'
+cfg.write(open(path, 'w'))
diff --git a/ethel/chroot.py b/ethel/chroot.py
index d85a705..a87a8e3 100644
--- a/ethel/chroot.py
+++ b/ethel/chroot.py
@@ -6,11 +6,20 @@ import sys
 import os
 
 
-def get_mount_point(session):
+def get_session_file(session):
+    return '/var/lib/schroot/session/%s' % (session)
+
+
+def get_session(session):
     cfg = configparser.ConfigParser()
-    fil = '/var/lib/schroot/session/%s' % (session)
+    fil = get_session_file(session)
     if cfg.read(fil) == []:
         raise KeyError("No such session: `%s' - %s" % (session, fil))
+    return cfg
+
+
+def get_mount_point(session):
+    cfg = get_session(session)
     obj = cfg[session]
     return obj['mount-location']
 
@@ -48,14 +57,23 @@ def scmd(session, command, expected=0, user=None):
 
 
 @contextlib.contextmanager
-def schroot(chroot):
+def schroot(chroot, source=False):
     session = "ethel-%s" % (os.getpid())
-    out, err = safe_run(['schroot', '-b', '-n', session, '-c', chroot])
+    chroot_name = chroot
+    os.environ['CHROOT_FILE_REPACK'] = "false"
+    if source:
+        os.environ['CHROOT_FILE_REPACK'] = "true"
+        chroot_name = "source:%s" % (chroot_name)
+
+    out, err = safe_run(['schroot', '-b', '-n', session, '-c', chroot_name])
 
     try:
         session = out.strip()
         print("[ethel] Started session: %s" % (session))
         yield session
+    except Exception:
+        os.environ['CHROOT_FILE_REPACK'] = "false"
+        raise
     finally:
         out, err = safe_run(['schroot', '-e', '-c', session])
 
@@ -64,3 +82,13 @@ def copy(session, source, dest):
     root = get_mount_point(session)
     dest = os.path.join(root, dest)
     return shutil.copy2(source, dest)
+
+
+def update(chroot):
+    with schroot(chroot, source=True) as session:
+        scmd(session, ['apt-get', 'update'], user='root')
+        scmd(session, ['apt-get', '-y', 'dist-upgrade'], user='root')
+
+
+def run_update():
+    update(*sys.argv[1:])
diff --git a/setup.py b/setup.py
index c5476f5..925d1eb 100755
--- a/setup.py
+++ b/setup.py
@@ -24,6 +24,7 @@ setup(
             'ethel-next = ethel.cli:next',
             'ethel-close = ethel.cli:close',
             'ethel-adequate = ethel.commands.adequate:main',
+            'ethel-update = ethel.chroot:run_update',
             'ethel-piuparts = ethel.commands.piuparts:main',
         ],
     }

-- 
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