cleanin up coding conventions
This commit is contained in:
@@ -37,10 +37,20 @@ def asc2png(inFile,outFile):
|
||||
|
||||
scipy.misc.imsave(outFile, im)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser=ArgumentParser(description="Convert image to ascii, or ascii to image. If only input is defined, it is assumed as image (PNG).")
|
||||
parser.add_argument('input', action="store")
|
||||
parser.add_argument('output', action="store", nargs='?')
|
||||
parser = ArgumentParser(
|
||||
description = "Convert image to ascii, or ascii to image. If only input is defined, it is assumed as image (PNG)."
|
||||
)
|
||||
parser.add_argument(
|
||||
'input',
|
||||
action = "store"
|
||||
)
|
||||
parser.add_argument(
|
||||
'output',
|
||||
action = "store",
|
||||
nargs = '?'
|
||||
)
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.output == None:
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
import sys,re,os
|
||||
from argparse import ArgumentParser
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
def setup_options():
|
||||
parser=ArgumentParser(description="""Template Filler
|
||||
parser = ArgumentParser(
|
||||
description="""Template Filler
|
||||
|
||||
=== Template example: ===
|
||||
Hello [[name]]!
|
||||
@@ -12,18 +14,39 @@ def setup_options():
|
||||
== Value file/Value pair example: ==
|
||||
[[name]]=John
|
||||
[[letter]]=@letter.txt
|
||||
""",formatter_class=RawTextHelpFormatter)
|
||||
parser.add_argument("-e",action="store_true",dest="env",default=False,
|
||||
help="Use the environment to replace ${env} style variables.")
|
||||
parser.add_argument("-f",action="store",dest="file",
|
||||
help="File name to read keys/values.")
|
||||
parser.add_argument("-p",action="append",dest="values",default=[],
|
||||
help="key=value pairs. This option may be issued several times.")
|
||||
parser.add_argument('template', action="store", nargs='?',
|
||||
help="Template file to be filled. If not defined, stdin used.")
|
||||
""",
|
||||
formatter_class = RawTextHelpFormatter
|
||||
)
|
||||
parser.add_argument(
|
||||
"-e",
|
||||
action = "store_true",
|
||||
dest = "env",
|
||||
default = False,
|
||||
help = "Use the environment to replace ${env} style variables."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f",
|
||||
action = "store",
|
||||
dest = "file",
|
||||
help = "File name to read keys/values."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
action = "append",
|
||||
dest = "values",
|
||||
default = [],
|
||||
help = "key=value pairs. This option may be issued several times."
|
||||
)
|
||||
parser.add_argument(
|
||||
'template',
|
||||
action = "store",
|
||||
nargs = '?',
|
||||
help = "Template file to be filled. If not defined, stdin used."
|
||||
)
|
||||
options = parser.parse_args()
|
||||
return options
|
||||
|
||||
|
||||
def parse_file(filename):
|
||||
pairs = []
|
||||
with open(filename, "r") as reader:
|
||||
@@ -33,7 +56,9 @@ def parse_file(filename):
|
||||
continue
|
||||
tokens = l.split('=', 1)
|
||||
if len(tokens) != 2:
|
||||
print("File %s:%i key=value pair '%s' does not parse"%(filename,i+1,l,))
|
||||
print("File %s:%i key=value pair '%s' does not parse"%(
|
||||
filename, i+1, l,
|
||||
))
|
||||
sys.exit(1)
|
||||
pairs.append( (tokens[0], tokens[1].decode('string_escape')) )
|
||||
return pairs
|
||||
@@ -48,6 +73,8 @@ def parse_arguments(args):
|
||||
pairs.append( (tokens[0], tokens[1].decode('string_escape')) )
|
||||
return pairs
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
options = setup_options();
|
||||
pairs = []
|
||||
if options.file != None:
|
||||
|
||||
Reference in New Issue
Block a user