Simplify the header string write
Instead of writing each line separate, build the full header string in one set
This commit is contained in:
@@ -339,18 +339,13 @@ def shortenPath(path, length = 30):
|
|||||||
return path;
|
return path;
|
||||||
|
|
||||||
# METHOD: printHeader
|
# METHOD: printHeader
|
||||||
# PARAMS: header string, header seperator, line counter, print header counter trigger
|
# PARAMS: header string, line counter, print header counter trigger
|
||||||
# RETURN: line counter +1
|
# RETURN: line counter +1
|
||||||
# DESC : prints header line and header seperator line
|
# DESC : prints header line and header seperator line
|
||||||
def printHeader(header, header_seperator, lines = 0, header_line = 0):
|
def printHeader(header, lines = 0, header_line = 0):
|
||||||
if lines == header_line:
|
if lines == header_line:
|
||||||
# blank line, might be used for page numbers, or other info
|
|
||||||
print("{}".format(''))
|
|
||||||
# print header
|
# print header
|
||||||
print("{}".format(header))
|
print("{}".format(header))
|
||||||
# print line with length of header string
|
|
||||||
# print("{}".format('-' * len(header)))
|
|
||||||
print("{}".format(header_seperator))
|
|
||||||
lines += 1
|
lines += 1
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
@@ -695,8 +690,15 @@ if args.read_only:
|
|||||||
format_length['city'],
|
format_length['city'],
|
||||||
format_length['location']
|
format_length['location']
|
||||||
)
|
)
|
||||||
# header line
|
# header line format:
|
||||||
header = format_line.format(
|
# blank line
|
||||||
|
# header title
|
||||||
|
# seperator line
|
||||||
|
header_line = '''{}
|
||||||
|
{}
|
||||||
|
{}'''.format(
|
||||||
|
'', # can later be set to something else, eg page numbers
|
||||||
|
format_line.format( # the header title line
|
||||||
filename = "File",
|
filename = "File",
|
||||||
latitude = "Latitude",
|
latitude = "Latitude",
|
||||||
longitude = "Longitude",
|
longitude = "Longitude",
|
||||||
@@ -705,9 +707,8 @@ if args.read_only:
|
|||||||
state = 'State',
|
state = 'State',
|
||||||
city = 'City',
|
city = 'City',
|
||||||
location = 'Location'
|
location = 'Location'
|
||||||
)
|
),
|
||||||
# header seperator line
|
"{}+{}+{}+{}+{}+{}+{}+{}".format( # the header seperator line
|
||||||
header_seperator = "{}+{}+{}+{}+{}+{}+{}+{}".format(
|
|
||||||
'-' * (format_length['filename'] + 2),
|
'-' * (format_length['filename'] + 2),
|
||||||
'-' * (format_length['latitude'] + 2),
|
'-' * (format_length['latitude'] + 2),
|
||||||
'-' * (format_length['longitude'] + 2),
|
'-' * (format_length['longitude'] + 2),
|
||||||
@@ -717,8 +718,9 @@ if args.read_only:
|
|||||||
'-' * (format_length['city'] + 2),
|
'-' * (format_length['city'] + 2),
|
||||||
'-' * (format_length['location'] + 2)
|
'-' * (format_length['location'] + 2)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
# print header
|
# print header
|
||||||
printHeader(header, header_seperator)
|
printHeader(header_line)
|
||||||
# now we just loop through each file and work on them
|
# now we just loop through each file and work on them
|
||||||
for xmp_file in work_files:
|
for xmp_file in work_files:
|
||||||
if not args.read_only:
|
if not args.read_only:
|
||||||
@@ -767,7 +769,7 @@ for xmp_file in work_files:
|
|||||||
if args.read_only:
|
if args.read_only:
|
||||||
# for read only we print out the data formatted
|
# for read only we print out the data formatted
|
||||||
# headline check, do we need to print that
|
# headline check, do we need to print that
|
||||||
count['read'] = printHeader(header, header_seperator, count['read'], header_repeat)
|
count['read'] = printHeader(header_line, count['read'], header_repeat)
|
||||||
# the data content
|
# the data content
|
||||||
print(format_line.format(
|
print(format_line.format(
|
||||||
filename = shortenPath(xmp_file, format_length['filename']), # shorten from the left
|
filename = shortenPath(xmp_file, format_length['filename']), # shorten from the left
|
||||||
|
|||||||
Reference in New Issue
Block a user