-
Notifications
You must be signed in to change notification settings - Fork 1
/
syshelp.py
23 lines (21 loc) · 827 Bytes
/
syshelp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# file: syshelp.py
# author: Colin Woodbury
# contact: colingw AT gmail
# about: Help with system tasks.
import sys
def get_args(oper='EXACTLY', num=1):
'''Checks args on the command line and returns them if valid.
Examples of use:
get_args() # Looks for exactly 1 arg.
get_args('EXACTLY', 2) # Looks for exactly 2 args.
get_args('AT_LEAST', 0) # Will accept any number of args.
get_args('AT_LEAST', 2) # Looks for two or more args.
'''
comps = {'EXACTLY': '!=', 'AT_LEAST': '<'}
if oper not in comps:
print('Bad comparison keyword -> {0}'.format(oper))
return
if eval('len(sys.argv) {0} num + 1'.format(comps[oper])):
print('Bad number of args ->', sys.argv[1:])
return
return sys.argv[1:] # Returns [] when len(sys.argv) < 2