-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cli arg parsing and help messages.
- Loading branch information
1 parent
9eb64ee
commit d455555
Showing
16 changed files
with
266 additions
and
236 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
#!/usr/bin/env python | ||
# This file should be compatible with both Python 2 and 3. | ||
# If it is not, please file a bug report. | ||
import sys | ||
import sys,optparse | ||
|
||
import subuserlib.installTime | ||
import subuserlib.commandLineArguments | ||
|
||
def parseCliArgs(): | ||
usage = "usage: subuser %prog" | ||
description = """ Display the current time in properly formated utc. Useful for setting the last-update-time attribute in permissions.json | ||
""" | ||
parser = optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription()) | ||
return parser.parse_args() | ||
|
||
if len(sys.argv) == 1: | ||
print(subuserlib.installTime.currentTimeString()) | ||
parseCliArgs() | ||
print(subuserlib.installTime.currentTimeString()) | ||
|
||
else: | ||
print(""" Display the current time in properly formated utc. Useful for setting the last-update-time attribute in permissions.json """) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
#!/usr/bin/env python | ||
# This file should be compatible with both Python 2 and 3. | ||
# If it is not, please file a bug report. | ||
import sys | ||
import optparse | ||
import subuserlib.describe | ||
import subuserlib.commandLineArguments | ||
|
||
def printHelp(): | ||
print("""Show basic information about a program: Whether it is installed, what it's permissions are ect. | ||
def parseCliArgs(): | ||
usage = "usage: subuser %prog PROGRAM_NAME(s)" | ||
description = """Show basic information about a program: Whether it is installed, what it's permissions are ect. | ||
Ex: | ||
$ subuser describe firefox | ||
<lots of info> | ||
""") | ||
""" | ||
parser = optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription()) | ||
return parser.parse_args() | ||
|
||
################################################################################################# | ||
if len(sys.argv) == 1 or {"help","-h","--help"} & set(sys.argv[]): | ||
printHelp() | ||
sys.exit() | ||
################################################################################################# | ||
(options,args) = parseCliArgs() | ||
|
||
for program in sys.argv[1:]: | ||
for program in args: | ||
subuserlib.describe.printInfo(program,True) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,36 @@ | ||
#!/usr/bin/env python | ||
# This file should be compatible with both Python 2 and 3. | ||
# If it is not, please file a bug report. | ||
import sys | ||
import os | ||
import sys,os,optparse | ||
|
||
import subuserlib.availablePrograms | ||
import subuserlib.install | ||
import subuserlib.describe | ||
import subuserlib.commandLineArguments | ||
|
||
def printHelp(): | ||
""" | ||
Display a help message for the install mode of the subuser command. | ||
""" | ||
print("""To install packages list there names: | ||
$ subuser install vim firefox | ||
def parseCliArgs(): | ||
usage = "usage: subuser %prog [options] PROGRAM_NAME(s)" | ||
description = """Install a set of subuser programs. To view a list of programs that can be installed try: | ||
Options: | ||
--from-cache build this image using layers from the cache | ||
$ subuser install vim --from-cache | ||
""") | ||
$ subuser list available | ||
""" | ||
parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription()) | ||
advancedOptions = subuserlib.commandLineArguments.advancedInstallOptionsGroup(parser) | ||
parser.add_option_group(advancedOptions) | ||
return parser.parse_args() | ||
|
||
################################################################################################# | ||
if len(sys.argv) == 1 or sys.argv[1] == "help" or sys.argv[1] == "-h" or sys.argv[1] == "--help": | ||
printHelp() | ||
sys.exit() | ||
################################################################################################# | ||
|
||
commandOptionList = ['--from-cache'] | ||
userProgramList, userOptionList = subuserlib.commandLineArguments.parseCommandLineArgs(sys.argv[1:], commandOptionList) | ||
|
||
# Are we to use layers from the cache when building the docker image: only for Dockerfiles build images | ||
useCache = False | ||
if '--from-cache' in userOptionList: | ||
useCache = True | ||
options,userProgramList = parseCliArgs() | ||
|
||
for program in userProgramList: | ||
print(program) | ||
subuserlib.install.installProgramAndDependencies(program, useCache) | ||
subuserlib.install.installProgramAndDependencies(program, options.useCache) | ||
|
||
#print for the MAIN program (The user called not the dependency the permission) | ||
#print for the MAIN program () | ||
print("\n============= INSTALLATION OK =============\n\n") | ||
for program in userProgramList: | ||
#there is too much output: a user will hardly recognize the nice info provided: add some space | ||
#there is too much output: a user will hardly recognize the usefull information provided: add some space | ||
print("\n{0}: has been installed with the following permissions.".format(program)) | ||
subuserlib.describe.printInfo(program,False) | ||
print("You can change this program's permissions at any time by editing it's permissions.json file.") |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,24 @@ | ||
#!/usr/bin/env python | ||
# This file should be compatible with both Python 2 and 3. | ||
# If it is not, please file a bug report. | ||
import sys | ||
import optparse | ||
import subuserlib.installTime | ||
import subuserlib.permissions | ||
import subuserlib.availablePrograms | ||
import subuserlib.paths | ||
import subuserlib.commandLineArguments | ||
|
||
def printHelp(): | ||
print(""" | ||
def parseCliArgs(): | ||
usage = "usage: subuser %prog PROGRAM_NAME(s)" | ||
description = """ | ||
Mark a program as needing to be updated. Note, that this may mess up the formatting of it's permissions.json file. | ||
Usage: | ||
$ subuser mark-as-needing-update program-name | ||
""") | ||
""" | ||
parser=optparse.OptionParser(usage=usage,description=description,formatter=subuserlib.commandLineArguments.HelpFormatterThatDoesntReformatDescription()) | ||
return parser.parse_args() | ||
|
||
################################################################################################# | ||
if len(sys.argv) == 1 or sys.argv[1] == "help" or sys.argv[1] == "-h" or sys.argv[1] == "--help": | ||
printHelp() | ||
sys.exit() | ||
################################################################################################# | ||
|
||
programName = sys.argv[1] | ||
options,programNames = parseCliArgs() | ||
|
||
if not subuserlib.availablePrograms.available(programName): | ||
print(programName+ " is not the name of any known program. Cannot mark it as having an update.") | ||
print("\nAvailable programs are: ") | ||
availableProgramsPath = subuserlib.paths.getAvailableProgramsPath() | ||
print(' '.join(sorted([program for program in os.listdir(availableProgramsPath)]))) | ||
else: | ||
permissions = subuserlib.permissions.getPermissions(programName) | ||
permissions["last-update-time"] = subuserlib.installTime.currentTimeString() | ||
subuserlib.permissions.setPermissions(programName,permissions) | ||
for program in programNames: | ||
subuserlib.installTime.markProgramAsNeedingUpdate(program) |
Oops, something went wrong.