File: version.py

package info (click to toggle)
subuser 0.6.2-3
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 4,208 kB
  • sloc: python: 5,201; sh: 380; makefile: 73
file content (38 lines) | stat: -rwxr-xr-x 1,274 bytes parent folder | download
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#external imports
import json
import sys
import optparse
#internal imports
import subuserlib.version
import subuserlib.commandLineArguments
import subuserlib.profile
from subuserlib.classes.user import User

def parseCliArgs(realArgs):
  usage = "usage: subuser version"
  description = """Prints subuser's version and other usefull debugging info.
"""
  parser = optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  parser.add_option("--json",dest="json",action="store_true",default=False,help="Display results in JSON format.")
  return parser.parse_args(args=realArgs)

@subuserlib.profile.do_cprofile
def runCommand(realArgs):
  """
  >>> import version #import self
  >>> version.runCommand([])
  Subuser version: 0.5
  Docker info:
   Foo: bar
  """
  user = User()
  (options,args) = parseCliArgs(realArgs)
  if options.json:
    print(json.dumps(subuserlib.version.getInfo(user),indent=1,separators=(",",": ")))
  else:
    print("Subuser version: " + subuserlib.version.getSubuserVersion(user))
    print("Docker info:")
    for key,value in subuserlib.version.getDockerInfo(user).items():
      print(" "+key+": "+str(value))