Move out session support.
This commit is contained in:
parent
568de5b03e
commit
c6d8ce59c0
5 changed files with 65 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
build
|
||||
*~
|
||||
ognibuild.egg-info
|
||||
dist
|
||||
|
|
|
@ -225,17 +225,3 @@ def run_dist(session):
|
|||
run_with_build_fixer(session, ['make', 'dist'])
|
||||
|
||||
raise NoBuildToolsFound()
|
||||
|
||||
|
||||
class PlainSession(object):
|
||||
"""Session ignoring user."""
|
||||
|
||||
def create_home(self):
|
||||
pass
|
||||
|
||||
def check_call(self, args):
|
||||
return subprocess.check_call(args)
|
||||
|
||||
def Popen(self, args, stdout=None, stderr=None, user=None, cwd=None):
|
||||
return subprocess.Popen(
|
||||
args, stdout=stdout, stderr=stderr, cwd=cwd)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
from . import PlainSession, run_dist, NoBuildToolsFound, note
|
||||
from . import run_dist, NoBuildToolsFound, note
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -27,8 +27,16 @@ def main():
|
|||
parser.add_argument(
|
||||
'--directory', '-d', type=str, help='Directory for project.',
|
||||
default='.')
|
||||
parser.add_argument(
|
||||
'--schroot', type=str, help='schroot to run in.')
|
||||
args = parser.parse_args()
|
||||
if args.schroot:
|
||||
from .session.schroot import SchrootSession
|
||||
session = SchrootSession(args.schroot)
|
||||
else:
|
||||
from .session.plain import PlainSession
|
||||
session = PlainSession()
|
||||
with session:
|
||||
os.chdir(args.directory)
|
||||
try:
|
||||
if args.subcommand == 'dist':
|
||||
|
@ -38,4 +46,5 @@ def main():
|
|||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
sys.exit(main())
|
||||
|
|
35
ognibuild/session/plain.py
Normal file
35
ognibuild/session/plain.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright (C) 2019-2020 Jelmer Vernooij <jelmer@jelmer.uk>
|
||||
# encoding: utf-8
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from . import Session
|
||||
|
||||
import subprocess
|
||||
|
||||
|
||||
class PlainSession(Session):
|
||||
"""Session ignoring user."""
|
||||
|
||||
def create_home(self):
|
||||
pass
|
||||
|
||||
def check_call(self, args):
|
||||
return subprocess.check_call(args)
|
||||
|
||||
def Popen(self, args, stdout=None, stderr=None, user=None, cwd=None):
|
||||
return subprocess.Popen(
|
||||
args, stdout=stdout, stderr=stderr, cwd=cwd)
|
|
@ -21,7 +21,10 @@ import subprocess
|
|||
from typing import Optional, List, Dict
|
||||
|
||||
|
||||
class Session(object):
|
||||
from . import Session, SessionSetupFailure
|
||||
|
||||
|
||||
class SchrootSession(Session):
|
||||
|
||||
_cwd: Optional[str]
|
||||
_location: Optional[str]
|
||||
|
@ -44,8 +47,12 @@ class Session(object):
|
|||
['schroot', '-c', 'session:' + self.session_id, '-e'])
|
||||
|
||||
def __enter__(self) -> 'Session':
|
||||
try:
|
||||
self.session_id = subprocess.check_output(
|
||||
['schroot', '-c', self.chroot, '-b']).strip().decode()
|
||||
except subprocess.CalledProcessError:
|
||||
# TODO(jelmer): Capture stderr and forward in SessionSetupFailure
|
||||
raise SessionSetupFailure()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
Loading…
Add table
Reference in a new issue