Skip to content

Commit

Permalink
Switched to spaces from tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansb committed Mar 7, 2012
1 parent 87c7ef1 commit 08c46e5
Show file tree
Hide file tree
Showing 6 changed files with 945 additions and 937 deletions.
152 changes: 76 additions & 76 deletions ish/__init__.py
Expand Up @@ -28,92 +28,92 @@


def auth_info():
"""
Description: Get the information necessary to determine whether a user is
properly logged in
"""
Description: Get the information necessary to determine whether a user is
properly logged in
:rtype: tuple:
:return: A tuple of the exit code of 'klist -s' and of the output of 'klist'
"""
:rtype: tuple:
:return: A tuple of the exit code of 'klist -s' and of the output of 'klist'
"""

import subprocess
from tempfile import TemporaryFile
std = TemporaryFile()
subprocess.call(['klist'], stdout=std)
exit_status = subprocess.call(['klist', '-s'])
std.seek(0)
out_lines = std.read().split('\n')
std.close()
ret = {}
ret['code'] = exit_status
for line in out_lines:
if line.startswith('Default'):
(ret['user'], ret['domain']) = line.lower().split(' ')[2].split('@')
return ret
import subprocess
from tempfile import TemporaryFile
std = TemporaryFile()
subprocess.call(['klist'], stdout=std)
exit_status = subprocess.call(['klist', '-s'])
std.seek(0)
out_lines = std.read().split('\n')
std.close()
ret = {}
ret['code'] = exit_status
for line in out_lines:
if line.startswith('Default'):
(ret['user'], ret['domain']) = line.lower().split(' ')[2].split('@')
return ret


def check_auth():
auth = auth_info()
if auth['code'] is not 0:
return False
if not auth['domain'] == "csh.rit.edu":
return False
return True
autho = auth_info()
if autho['code'] is not 0:
return False
if not autho['domain'] == "csh.rit.edu":
return False
return True


def auth():
auth = auth_info()
if auth['code'] is not 0:
return "Ticket expired or invalid. Exit and run kinit"
if not auth['domain'] == "csh.rit.edu":
return "Not in domain 'csh.rit.edu'"
return "Successfully authenticated"
autho = auth_info()
if autho['code'] is not 0:
return "Ticket expired or invalid. Exit and run kinit"
if not autho['domain'] == "csh.rit.edu":
return "Not in domain 'csh.rit.edu'"
return "Successfully authenticated"


def get_username():
auth = auth_info()
if auth['code'] is not 0:
return False
return auth['user']
autho = auth_info()
if autho['code'] is not 0:
return False
return autho['user']


def ish_prompt(p, required=True, constraints=None):
val = None
while not val:
if not constraints:
val = raw_input(p + ": ")
else:
#alphabetize everything, lower case
constraints = sorted(constraints, key=str.lower)
opt_lists = []
options = {}
#create a dictionary with numbers as keys, the constraints as values
if len(constraints) <= 30:
options = dict(zip(range(len(constraints)), constraints))
else:
for count in range(int(len(constraints) / 30 + 1)):
opt_lists.append(constraints[count * 30:count * 30 + 30])
for segment in opt_lists:
options[len(options)] = "%s - %s" % (segment[0], segment[-1])
#use a lambda to make options formatted like:
# [0]: this
# [1]: that
# [2]: other
prompt = ("From choices:\n" + ''.join(map(lambda (k, v):
" [%s]; %s\n" % (k, v), options.items())) + p + ": ")
try:
print required
val = int(raw_input(prompt))
except ValueError:
if not required:
break
continue
if not val < len(options.values()):
val = None
elif len(constraints) <= 30:
val = options.values()[val]
else:
val = ish_prompt(p, required=required, constraints=opt_lists[val])
if not required:
break
return val
def ish_prompt(pro, required=True, constraints=None):
val = None
while not val:
if not constraints:
val = raw_input(pro + ": ")
else:
#alphabetize everything, lower case
constraints = sorted(constraints, key=str.lower)
opt_lists = []
options = {}
#create a dictionary with numbers as keys, the constraints as values
if len(constraints) <= 30:
options = dict(zip(range(len(constraints)), constraints))
else:
for count in range(int(len(constraints) / 30 + 1)):
opt_lists.append(constraints[count * 30:count * 30 + 30])
for segment in opt_lists:
options[len(options)] = "%s - %s" % (segment[0], segment[-1])
#use a lambda to make options formatted like:
# [0]: this
# [1]: that
# [2]: other
prompt = ("From choices:\n" + ''.join(map(lambda (k, v):
" [%s]; %s\n" % (k, v), options.items())) + pro + ": ")
try:
print required
val = int(raw_input(prompt))
except ValueError:
if not required:
break
continue
if not val < len(options.values()):
val = None
elif len(constraints) <= 30:
val = options.values()[val]
else:
val = ish_prompt(pro, required=required, constraints=opt_lists[val])
if not required:
break
return val

0 comments on commit 08c46e5

Please sign in to comment.