[Python-modules-commits] r25564 - in packages/python-schroot/trunk (37 files)

paultag at users.alioth.debian.org paultag at users.alioth.debian.org
Wed Aug 14 18:32:09 UTC 2013


    Date: Wednesday, August 14, 2013 @ 18:32:07
  Author: paultag
Revision: 25564

[svn-inject] Applying Debian modifications (0.3-1) to trunk

Added:
  packages/python-schroot/trunk/debian/
  packages/python-schroot/trunk/debian/changelog
  packages/python-schroot/trunk/debian/compat
  packages/python-schroot/trunk/debian/control
  packages/python-schroot/trunk/debian/copyright
  packages/python-schroot/trunk/debian/rules
  packages/python-schroot/trunk/debian/source/
  packages/python-schroot/trunk/debian/source/format
  packages/python-schroot/trunk/debian/usr/
  packages/python-schroot/trunk/debian/usr/lib/
  packages/python-schroot/trunk/debian/usr/lib/python2.7/
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/PKG-INFO
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/SOURCES.txt
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/dependency_links.txt
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/top_level.txt
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/__init__.py
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/chroot.py
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/core.py
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/errors.py
  packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/utils.py
  packages/python-schroot/trunk/debian/usr/lib/python3/
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/PKG-INFO
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/SOURCES.txt
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/dependency_links.txt
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/top_level.txt
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/__init__.py
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/__pycache__/
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/chroot.py
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/core.py
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/errors.py
  packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/utils.py


Property changes on: packages/python-schroot/trunk/debian
___________________________________________________________________
Added: mergeWithUpstream
   + 1

Added: packages/python-schroot/trunk/debian/changelog
===================================================================
--- packages/python-schroot/trunk/debian/changelog	                        (rev 0)
+++ packages/python-schroot/trunk/debian/changelog	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,5 @@
+python-schroot (0.3-1) unstable; urgency=low
+
+  * Initial release.
+
+ -- Paul Tagliamonte <paultag at debian.org>  Wed, 14 Aug 2013 01:10:13 -0400

Added: packages/python-schroot/trunk/debian/compat
===================================================================
--- packages/python-schroot/trunk/debian/compat	                        (rev 0)
+++ packages/python-schroot/trunk/debian/compat	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+9

Added: packages/python-schroot/trunk/debian/control
===================================================================
--- packages/python-schroot/trunk/debian/control	                        (rev 0)
+++ packages/python-schroot/trunk/debian/control	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,39 @@
+Source: python-schroot
+Section: python
+Priority: optional
+Maintainer: Debian Python Modules Team <python-modules-team at lists.alioth.debian.org>
+Uploaders: Paul Tagliamonte <paultag at debian.org>
+Build-Depends:
+ debhelper (>= 9),
+ python-all,
+ python3-all,
+Standards-Version: 3.9.4
+Homepage: https://github.com/paultag/python-schroot
+Vcs-Svn: svn://anonscm.debian.org/python-modules/packages/python-schroot/trunk/
+Vcs-Browser: http://anonscm.debian.org/viewvc/python-modules/packages/python-schroot/trunk/
+X-Python-Version: >= 2.7
+X-Python3-Version: >= 3.2
+
+Package: python-schroot
+Architecture: all
+Depends: ${misc:Depends}, ${python:Depends}
+Description: set of Python bindings to schroot chroots
+ Ever want to chroot into schroot chroots in Python? Today's your lucky
+ day! You can schroot your chroots all day long with this miracle of science.
+ .
+ This package contains a set of Python wrappers to the schroot(1) binary, to
+ enable programmatic access to schroot containers.
+ .
+ This package contains the Python 2 bindings only.
+
+Package: python3-schroot
+Architecture: all
+Depends: ${misc:Depends}, ${python3:Depends}
+Description: set of Python 3 bindings to schroot chroots
+ Ever want to chroot into schroot chroots in Python? Today's your lucky
+ day! You can schroot your chroots all day long with this miracle of science.
+ .
+ This package contains a set of Python wrappers to the schroot(1) binary, to
+ enable programmatic access to schroot containers.
+ .
+ This package contains the Python 3 bindings only.

Added: packages/python-schroot/trunk/debian/copyright
===================================================================
--- packages/python-schroot/trunk/debian/copyright	                        (rev 0)
+++ packages/python-schroot/trunk/debian/copyright	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,25 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
+Upstream-Name: python-schroot
+Upstream-Contact: Paul Tagliamonte <paultag at debian.org>
+Source: https://github.com/paultag/python-schroot/
+
+Files: *
+Copyright: 2013, Paul Tagliamonte <paultag at debian.org>
+License: Expat
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+ .
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.

Added: packages/python-schroot/trunk/debian/rules
===================================================================
--- packages/python-schroot/trunk/debian/rules	                        (rev 0)
+++ packages/python-schroot/trunk/debian/rules	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,34 @@
+#!/usr/bin/make -f
+
+PY2_PACKAGE_NAME = python-schroot
+PY3_PACKAGE_NAME = python3-schroot
+
+PYVERS  = $(shell pyversions -r)
+PY3VERS = $(shell py3versions -r)
+
+%:
+	dh $@ --with python2,python3
+
+override_dh_auto_clean:
+	dh_auto_clean
+	rm -rvf ./*.egg-info ./build
+
+override_dh_auto_build:
+	set -xe; \
+	for py in $(PYVERS) $(PY3VERS); do \
+		$$py setup.py build; \
+	done
+
+override_dh_auto_install:
+	set -xe; \
+	for py in $(PYVERS); do \
+		$$py setup.py install --skip-build --root debian/$(PY2_PACKAGE_NAME) \
+		--install-layout deb; \
+	done
+	set -xe; \
+		for py in $(PY3VERS); do \
+		$$py setup.py install --skip-build --root debian/$(PY3_PACKAGE_NAME) \
+		--install-layout deb; \
+	done
+	# Remove me when dh_python2 can handle this file
+	rm -vf debian/*/usr/lib/python*/*-packages/*.egg-info/SOURCES.txt


Property changes on: packages/python-schroot/trunk/debian/rules
___________________________________________________________________
Added: svn:executable
   + *

Added: packages/python-schroot/trunk/debian/source/format
===================================================================
--- packages/python-schroot/trunk/debian/source/format	                        (rev 0)
+++ packages/python-schroot/trunk/debian/source/format	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+3.0 (quilt)

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/__init__.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/__init__.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/__init__.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,4 @@
+from schroot.chroot import schroot  # noqa
+
+__appname__ = "schroot"
+__version__ = "0.3"

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/chroot.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/chroot.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/chroot.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,154 @@
+from schroot.utils import run_command
+from schroot.core import log
+from schroot.errors import SchrootError
+
+from contextlib import contextmanager
+import shutil
+import os
+import subprocess
+
+try:
+    import configparser
+except ImportError:
+    import ConfigParser as configparser  # meh, Python 2
+
+
+class SchrootCommandError(SchrootError):
+    pass
+
+
+SCHROOT_BASE = "/var/lib/schroot"
+
+
+class SchrootChroot(object):
+    __slots__ = ('session', 'active', 'location')
+
+    def __init__(self):
+        self.session = None
+        self.active = False
+        self.location = None
+
+    def _command(self, cmd, kwargs):
+        user = kwargs.pop("user", None)
+        preserve_environment = kwargs.pop("preserve_environment", False)
+
+        command = ['schroot', '-r', '-c', self.session]
+        if user:
+            command += ['-u', user]
+        if preserve_environment:
+            command += ['-p']
+        command += ['--'] + cmd
+        log.debug(" ".join((str(x) for x in command)))
+        return command
+
+    def _safe_run(self, cmd):
+        # log.debug("Command: %s" % (" ".join(cmd)))
+        out, err, ret = run_command(cmd)
+        if ret != 0:
+            raise SchrootCommandError()
+        return out, err, ret
+
+    def copy(self, what, whence, user=None):
+        o, e, r = self.run(["mktemp", "-d"],
+                           return_codes=0)  # Don't pass user.
+        # it'll set the perms wonky.
+        where = o.strip()
+        try:
+            what = os.path.abspath(what)
+            fname = os.path.basename(what)
+            internal = os.path.join(where, fname)
+            pth = os.path.join(self.location, internal.lstrip(os.path.sep))
+            shutil.copy(what, pth)
+            self.run(['mv', internal, whence], user=user, return_codes=0)
+        finally:
+            self.run(['rm', '-rf', where], user=user, return_codes=0)
+
+    def get_session_config(self):
+        cfg = configparser.ConfigParser()
+        fil = os.path.join(SCHROOT_BASE, 'session', self.session)
+        if cfg.read(fil) == []:
+            raise SchrootError("SANITY FAILURE")
+        return cfg[self.session]
+
+    def start(self, chroot_name):
+        out, err, ret = self._safe_run(['schroot', '-b', '-c', chroot_name])
+        self.session = out.strip()
+        self.active = True
+        log.debug("new session: %s" % (self.session))
+
+        out, err, ret = self._safe_run([
+            'schroot', '--location', '-c', "session:%s" % self.session
+        ])
+        self.location = out.strip()
+
+    def end(self):
+        if self.session is not None:
+            out, err, ret = self._safe_run(['schroot', '-e', '-c', self.session])
+
+    def __lt__(self, other):
+        return self.run(other, return_codes=0)
+
+    def __floordiv__(self, other):
+        return UserProxy(other, self)
+
+    @contextmanager
+    def create_file(self, whence, user=None):
+        o, e, r = self.run(["mktemp", "-d"],
+                           return_codes=0)  # Don't pass user.
+        # it'll set the perms wonky.
+        where = o.strip()
+        fname = os.path.basename(whence)
+        internal = os.path.join(where, fname)
+        pth = os.path.join(self.location, internal.lstrip(os.path.sep))
+        log.debug("creating %s" % (pth))
+        try:
+            with open(pth, "w") as f:
+                yield f
+            log.debug("copy %s to %s" % (internal, whence))
+            self.run(['mv', internal, whence], user=user, return_codes=0)
+        finally:
+            self.run(['rm', '-rf', where], return_codes=0)
+
+    def run(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return run_command(command, **kwargs)
+
+    def call(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.call(command, **kwargs)
+
+    def check_call(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.check_call(command, **kwargs)
+
+    def check_output(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.check_output(command, **kwargs)
+
+    def Popen(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.Popen(command, **kwargs)
+
+
+class UserProxy(SchrootChroot):
+    __slots__ = ('user')
+
+    def __init__(self, user, other):
+        super(UserProxy, self).__init__()
+        self.user = user
+        for entry in other.__slots__:
+            setattr(self, entry, getattr(other, entry))
+
+    def run(self, cmd, return_codes=None):
+        return super(UserProxy, self).run(cmd, user=self.user,
+                                          return_codes=return_codes)
+
+
+ at contextmanager
+def schroot(name):
+    ch = SchrootChroot()
+    try:
+        ch.start(name)
+        yield ch
+    finally:
+        ch.end()

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/core.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/core.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/core.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,13 @@
+import logging
+
+
+log = logging.getLogger('schroot')
+
+def set_debug():
+    log.setLevel(logging.DEBUG)
+    _ch = logging.StreamHandler()
+    _ch.setLevel(logging.DEBUG)
+    _formatter = logging.Formatter(
+        '[%(levelname)s] %(created)f: (%(funcName)s) %(message)s')
+    _ch.setFormatter(_formatter)
+    log.addHandler(_ch)

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/errors.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/errors.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/errors.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,4 @@
+
+
+class SchrootError(Exception):
+    pass

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/utils.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/utils.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot/utils.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,28 @@
+import subprocess
+import shlex
+
+
+def run_command(command, stdin=None, encoding='utf-8', return_codes=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) = (x.decode(encoding) for x in pipe.communicate(**kwargs))
+
+    if return_codes is not None:
+        if not isinstance(return_codes, tuple):
+            return_codes = (return_codes, )
+        if pipe.returncode not in return_codes:
+            raise SchrootCommandError("Bad return code %d" % pipe.returncode)
+
+    return (output, stderr, pipe.returncode)

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/PKG-INFO
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/PKG-INFO	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/PKG-INFO	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: schroot
+Version: 0.3
+Summary: schroot chroot schroots!
+Home-page: http://pault.ag/
+Author: Paul Tagliamonte
+Author-email: tag at pault.ag
+License: Expat
+Description: UNKNOWN
+Platform: any

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/SOURCES.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/SOURCES.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/SOURCES.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,10 @@
+setup.py
+schroot/__init__.py
+schroot/chroot.py
+schroot/core.py
+schroot/errors.py
+schroot/utils.py
+schroot.egg-info/PKG-INFO
+schroot.egg-info/SOURCES.txt
+schroot.egg-info/dependency_links.txt
+schroot.egg-info/top_level.txt
\ No newline at end of file

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/dependency_links.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/dependency_links.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/dependency_links.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+

Added: packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/top_level.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/top_level.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python2.7/dist-packages/schroot-0.3.egg-info/top_level.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+schroot

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/__init__.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/__init__.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/__init__.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,4 @@
+from schroot.chroot import schroot  # noqa
+
+__appname__ = "schroot"
+__version__ = "0.3"

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/chroot.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/chroot.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/chroot.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,154 @@
+from schroot.utils import run_command
+from schroot.core import log
+from schroot.errors import SchrootError
+
+from contextlib import contextmanager
+import shutil
+import os
+import subprocess
+
+try:
+    import configparser
+except ImportError:
+    import ConfigParser as configparser  # meh, Python 2
+
+
+class SchrootCommandError(SchrootError):
+    pass
+
+
+SCHROOT_BASE = "/var/lib/schroot"
+
+
+class SchrootChroot(object):
+    __slots__ = ('session', 'active', 'location')
+
+    def __init__(self):
+        self.session = None
+        self.active = False
+        self.location = None
+
+    def _command(self, cmd, kwargs):
+        user = kwargs.pop("user", None)
+        preserve_environment = kwargs.pop("preserve_environment", False)
+
+        command = ['schroot', '-r', '-c', self.session]
+        if user:
+            command += ['-u', user]
+        if preserve_environment:
+            command += ['-p']
+        command += ['--'] + cmd
+        log.debug(" ".join((str(x) for x in command)))
+        return command
+
+    def _safe_run(self, cmd):
+        # log.debug("Command: %s" % (" ".join(cmd)))
+        out, err, ret = run_command(cmd)
+        if ret != 0:
+            raise SchrootCommandError()
+        return out, err, ret
+
+    def copy(self, what, whence, user=None):
+        o, e, r = self.run(["mktemp", "-d"],
+                           return_codes=0)  # Don't pass user.
+        # it'll set the perms wonky.
+        where = o.strip()
+        try:
+            what = os.path.abspath(what)
+            fname = os.path.basename(what)
+            internal = os.path.join(where, fname)
+            pth = os.path.join(self.location, internal.lstrip(os.path.sep))
+            shutil.copy(what, pth)
+            self.run(['mv', internal, whence], user=user, return_codes=0)
+        finally:
+            self.run(['rm', '-rf', where], user=user, return_codes=0)
+
+    def get_session_config(self):
+        cfg = configparser.ConfigParser()
+        fil = os.path.join(SCHROOT_BASE, 'session', self.session)
+        if cfg.read(fil) == []:
+            raise SchrootError("SANITY FAILURE")
+        return cfg[self.session]
+
+    def start(self, chroot_name):
+        out, err, ret = self._safe_run(['schroot', '-b', '-c', chroot_name])
+        self.session = out.strip()
+        self.active = True
+        log.debug("new session: %s" % (self.session))
+
+        out, err, ret = self._safe_run([
+            'schroot', '--location', '-c', "session:%s" % self.session
+        ])
+        self.location = out.strip()
+
+    def end(self):
+        if self.session is not None:
+            out, err, ret = self._safe_run(['schroot', '-e', '-c', self.session])
+
+    def __lt__(self, other):
+        return self.run(other, return_codes=0)
+
+    def __floordiv__(self, other):
+        return UserProxy(other, self)
+
+    @contextmanager
+    def create_file(self, whence, user=None):
+        o, e, r = self.run(["mktemp", "-d"],
+                           return_codes=0)  # Don't pass user.
+        # it'll set the perms wonky.
+        where = o.strip()
+        fname = os.path.basename(whence)
+        internal = os.path.join(where, fname)
+        pth = os.path.join(self.location, internal.lstrip(os.path.sep))
+        log.debug("creating %s" % (pth))
+        try:
+            with open(pth, "w") as f:
+                yield f
+            log.debug("copy %s to %s" % (internal, whence))
+            self.run(['mv', internal, whence], user=user, return_codes=0)
+        finally:
+            self.run(['rm', '-rf', where], return_codes=0)
+
+    def run(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return run_command(command, **kwargs)
+
+    def call(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.call(command, **kwargs)
+
+    def check_call(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.check_call(command, **kwargs)
+
+    def check_output(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.check_output(command, **kwargs)
+
+    def Popen(self, cmd, **kwargs):
+        command = self._command(cmd, kwargs)
+        return subprocess.Popen(command, **kwargs)
+
+
+class UserProxy(SchrootChroot):
+    __slots__ = ('user')
+
+    def __init__(self, user, other):
+        super(UserProxy, self).__init__()
+        self.user = user
+        for entry in other.__slots__:
+            setattr(self, entry, getattr(other, entry))
+
+    def run(self, cmd, return_codes=None):
+        return super(UserProxy, self).run(cmd, user=self.user,
+                                          return_codes=return_codes)
+
+
+ at contextmanager
+def schroot(name):
+    ch = SchrootChroot()
+    try:
+        ch.start(name)
+        yield ch
+    finally:
+        ch.end()

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/core.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/core.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/core.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,13 @@
+import logging
+
+
+log = logging.getLogger('schroot')
+
+def set_debug():
+    log.setLevel(logging.DEBUG)
+    _ch = logging.StreamHandler()
+    _ch.setLevel(logging.DEBUG)
+    _formatter = logging.Formatter(
+        '[%(levelname)s] %(created)f: (%(funcName)s) %(message)s')
+    _ch.setFormatter(_formatter)
+    log.addHandler(_ch)

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/errors.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/errors.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/errors.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,4 @@
+
+
+class SchrootError(Exception):
+    pass

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/utils.py
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/utils.py	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot/utils.py	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,28 @@
+import subprocess
+import shlex
+
+
+def run_command(command, stdin=None, encoding='utf-8', return_codes=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) = (x.decode(encoding) for x in pipe.communicate(**kwargs))
+
+    if return_codes is not None:
+        if not isinstance(return_codes, tuple):
+            return_codes = (return_codes, )
+        if pipe.returncode not in return_codes:
+            raise SchrootCommandError("Bad return code %d" % pipe.returncode)
+
+    return (output, stderr, pipe.returncode)

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/PKG-INFO
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/PKG-INFO	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/PKG-INFO	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: schroot
+Version: 0.3
+Summary: schroot chroot schroots!
+Home-page: http://pault.ag/
+Author: Paul Tagliamonte
+Author-email: tag at pault.ag
+License: Expat
+Description: UNKNOWN
+Platform: any

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/SOURCES.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/SOURCES.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/SOURCES.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1,10 @@
+setup.py
+schroot/__init__.py
+schroot/chroot.py
+schroot/core.py
+schroot/errors.py
+schroot/utils.py
+schroot.egg-info/PKG-INFO
+schroot.egg-info/SOURCES.txt
+schroot.egg-info/dependency_links.txt
+schroot.egg-info/top_level.txt
\ No newline at end of file

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/dependency_links.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/dependency_links.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/dependency_links.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+

Added: packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/top_level.txt
===================================================================
--- packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/top_level.txt	                        (rev 0)
+++ packages/python-schroot/trunk/debian/usr/lib/python3/dist-packages/schroot-0.3.egg-info/top_level.txt	2013-08-14 18:32:07 UTC (rev 25564)
@@ -0,0 +1 @@
+schroot




More information about the Python-modules-commits mailing list