Permalink
Cannot retrieve contributors at this time
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?
gpfs-scan-files/User.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (30 sloc)
966 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |