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
|
||||||
|
|
||||||
@@ -672,7 +667,7 @@ if args.debug:
|
|||||||
# if we have read only we print list format style
|
# if we have read only we print list format style
|
||||||
if args.read_only:
|
if args.read_only:
|
||||||
# various string lengths
|
# various string lengths
|
||||||
format_length ={
|
format_length = {
|
||||||
'filename': 40,
|
'filename': 40,
|
||||||
'latitude': 18,
|
'latitude': 18,
|
||||||
'longitude': 18,
|
'longitude': 18,
|
||||||
@@ -695,30 +690,37 @@ 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
|
||||||
filename = "File",
|
# header title
|
||||||
latitude = "Latitude",
|
# seperator line
|
||||||
longitude = "Longitude",
|
header_line = '''{}
|
||||||
code = 'Code',
|
{}
|
||||||
country = 'Country',
|
{}'''.format(
|
||||||
state = 'State',
|
'', # can later be set to something else, eg page numbers
|
||||||
city = 'City',
|
format_line.format( # the header title line
|
||||||
location = 'Location'
|
filename = "File",
|
||||||
)
|
latitude = "Latitude",
|
||||||
# header seperator line
|
longitude = "Longitude",
|
||||||
header_seperator = "{}+{}+{}+{}+{}+{}+{}+{}".format(
|
code = 'Code',
|
||||||
'-' * (format_length['filename'] + 2),
|
country = 'Country',
|
||||||
'-' * (format_length['latitude'] + 2),
|
state = 'State',
|
||||||
'-' * (format_length['longitude'] + 2),
|
city = 'City',
|
||||||
'-' * (format_length['code'] + 2),
|
location = 'Location'
|
||||||
'-' * (format_length['country'] + 2),
|
),
|
||||||
'-' * (format_length['state'] + 2),
|
"{}+{}+{}+{}+{}+{}+{}+{}".format( # the header seperator line
|
||||||
'-' * (format_length['city'] + 2),
|
'-' * (format_length['filename'] + 2),
|
||||||
'-' * (format_length['location'] + 2)
|
'-' * (format_length['latitude'] + 2),
|
||||||
|
'-' * (format_length['longitude'] + 2),
|
||||||
|
'-' * (format_length['code'] + 2),
|
||||||
|
'-' * (format_length['country'] + 2),
|
||||||
|
'-' * (format_length['state'] + 2),
|
||||||
|
'-' * (format_length['city'] + 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