Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/python
import subprocess
def _ncheck_output(cmds):
if type(cmds )!=type([]): cmds = [cmds.split()]
if type(cmds[0])!=type([]): cmds = [cmds]
ncmds = len(cmds)
ps = ncmds*[None]
for i,cmd in enumerate(cmds):
if i==0:
ps[i] = subprocess.Popen(cmds[i], stdout=subprocess.PIPE, shell=False)
else:
ps[i] = subprocess.Popen(cmds[i], stdin=ps[i-1].stdout, stdout=subprocess.PIPE, shell=False)
for i in range(ncmds-1):
ps[i].stdout.close()
return ps[-1].communicate()[0]
class User:
def __init__(self):
self.data = {}
self.is_loaded = False
def get_user(self,uid):
if not self.data:
self.load_data()
return self.data.get(int(uid),"N/A-" + str(uid))
def load_data(self):
for line in _ncheck_output('ssh head1 getent passwd').split("\n"):
sline = line.strip()
if not sline or sline[0]=='#': continue
fields = sline.split(":")
self.data[int(fields[2])] = fields[0]
self.is_loaded = True