File: ps.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 (36 lines) | stat: -rwxr-xr-x 1,291 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-

#external imports
import sys
import optparse
import json
import os
import uuid
#internal imports
from subuserlib.classes.user import User
import subuserlib.commandLineArguments
import subuserlib.profile

def parseCliArgs(realArgs):
  usage = "usage: subuser ps"
  description = """ List running subusers.
  """
  parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription())
  parser.add_option("--internal",dest="internal",action="store_true",default=False,help="Include internal subusers in list.")
  return parser.parse_args(args=realArgs)

@subuserlib.profile.do_cprofile
def runCommand(realArgs):
  options,args = parseCliArgs(realArgs)
  user = User()
  runningImages = [container["Image"] for container in user.dockerDaemon.getContainers(onlyRunning=True)]
  for _,subuser in user.registry.subusers.items():
    try:
      if subuser.getRunReadyImage().id in runningImages:
        if not options.internal:
          if subuser.name.startswith("!"):
            continue
        print(subuser.name)
    except (KeyError,subuserlib.classes.subuserSubmodules.run.runtimeCache.NoRuntimeCacheForSubusersWhichDontHaveExistantImagesException):
      pass