/usr/lib/python3/dist-packages/subuserlib/docker.py is in subuser 0.6.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # -*- coding: utf-8 -*-
"""
This module helps us interact with the Docker executable directly.
"""
#external imports
import sys
import os
import getpass
import grp
#internal imports
import subuserlib.subprocessExtras as subprocessExtras
import subuserlib.executablePath
executable = None
verified = False
def getExecutable():
"""
Return the name of the docker executable or None if docker is not installed.
"""
global executable
if executable is not None:
return executable
if subuserlib.executablePath.which("docker.io"): # Docker is called docker.io on debian.
return "docker.io"
if subuserlib.executablePath.which("docker"):
return "docker"
return None
def getAndVerifyExecutable():
"""
Return the name of the docker executable. Exits and displays a user friendly error message if docker is not setup correctly.
"""
global executable
global verified
if executable is not None and verified:
return executable
executable = getExecutable()
if not executable:
sys.exit("""Error: Docker is not installed.
For installation instructions see <https://www.docker.io/gettingstarted/#h_installation>""")
if not os.path.exists("/var/run/docker.pid"):
sys.exit("""Error: Docker is not running. You can launch it as root with:
# docker -d
""")
verified = True
return executable
def run(args,cwd=None):
"""
Run docker with the given command line arguments. Return Docker's exit code.
"""
return subprocessExtras.call([getAndVerifyExecutable()]+args,cwd)
def runBackground(args,cwd=None,suppressOutput=True,collectStdout=False,collectStderr=False):
"""
Run docker with the given command line arguments. Return Docker's pid.
"""
return subprocessExtras.callBackground([getAndVerifyExecutable()]+args,cwd,suppressOutput=suppressOutput,collectStdout=collectStdout,collectStderr=collectStderr)
def buildImageTag(tag,hash):
tag ='{:-<95.95}{:-<32.32}'.format(tag,hash)
def isvalid(c):
if c in "-_.":
return True
return c.isalpha() or c.isdigit()
return ''.join([c if isvalid(c) else "-" for c in tag])
|