Skip to content

Commit 6b78912

Browse files
committed
WIP: linting progresses
1 parent 4eee540 commit 6b78912

8 files changed

+55
-62
lines changed

.pylintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ ignore-patterns=
2323
^(.+).html,
2424
^(.+).htm,
2525
^(.+).svg,
26+
^(.+).cfg,
27+
^(.+).prov,
28+
^(.+).notes,
2629
^\.,
2730

2831
ignore-paths=
@@ -33,3 +36,5 @@ ignore-paths=
3336
[MESSAGES CONTROL]
3437

3538
disable =
39+
C0301, # line too long.
40+
R0903, # too few public methods.
File renamed without changes.

src/anz_rosetta_csv/anz_rosetta_csv.py

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,12 @@
2727
logging.Formatter.converter = time.gmtime
2828

2929

30-
def createImportOverview(droidcsv, configfile):
31-
createoverview = ImportOverviewGenerator(droidcsv, configfile)
32-
createoverview.createOverviewSheet()
33-
34-
35-
def importsheetDROIDmapping(droidcsv, importschema, configfile):
36-
importgenerator = ImportSheetGenerator(droidcsv, importschema, configfile)
37-
importgenerator.droid2archwayimport()
38-
39-
40-
def exportsheetRosettamapping(
41-
droidcsv, exportsheet, rosettaschema, configfile, provenance
42-
):
43-
csvgen = RosettaCSVGenerator(
44-
droidcsv, exportsheet, rosettaschema, configfile, provenance
45-
)
46-
res = csvgen.export2rosettacsv()
47-
print(res)
48-
49-
5030
def main():
51-
# Usage: --csv [droid report]
52-
# Handle command line arguments for the script
31+
"""Primary entry point for this script."""
32+
5333
parser = argparse.ArgumentParser(
5434
description="Generate Archway Import Sheet and Rosetta Ingest CSV from DROID CSV Reports."
5535
)
56-
57-
# TODO: Consider optional and mandatory elements... behaviour might change depending on output...
58-
# other options droid csv and rosetta schema
59-
# NOTE: class on its own might be used to create a blank import csv with just static options
6036
parser.add_argument(
6137
"--csv", help="Single DROID CSV to read.", default=False, required=False
6238
)
@@ -89,12 +65,9 @@ def main():
8965

9066
if len(sys.argv) == 1:
9167
parser.print_help()
92-
sys.exit(1)
68+
sys.exit(0)
9369

94-
# Parse arguments into namespace object to reference later in the script
95-
global args
9670
args = parser.parse_args()
97-
9871
if args.args:
9972
config = ConfigParser.RawConfigParser()
10073
config.read(args.args)
@@ -108,13 +81,20 @@ def main():
10881
args.exp = config.get("arguments", "listcontrol")
10982
args.pro = config.get("arguments", "provenance")
11083

111-
# creating an ingest sheet for Rosetta...
11284
if args.csv and args.exp and args.ros and args.cfg:
113-
exportsheetRosettamapping(args.csv, args.exp, args.ros, args.cfg, args.pro)
114-
# we're not doing anything sensible...
115-
else:
116-
parser.print_help()
117-
sys.exit(1)
85+
csvgen = RosettaCSVGenerator(
86+
droidcsv=args.csv,
87+
exportsheet=args.exp,
88+
rosettaschema=args.ros,
89+
configfile=args.cfg,
90+
provenance=args.pro,
91+
)
92+
res = csvgen.export2rosettacsv()
93+
print(res)
94+
sys.exit()
95+
96+
parser.print_help()
97+
sys.exit()
11898

11999

120100
if __name__ == "__main__":
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
#!/usr/local/bin/python
2-
# -*- coding: utf-8 -*-
1+
"""Functions shared with the Collections Import Sheet Generator."""
2+
3+
# pylint: disable=R0903
34

45

56
class ImportSheetGenerator:
7+
"""Import Sheet Generator Class."""
8+
69
def get_title(self, title):
10+
"""Return a title from a filename string."""
711
return title.rsplit(".", 1)[
812
0
913
].rstrip() # split once at full-stop (assumptuon 'ext' follows)

src/anz_rosetta_csv/provenance_csv_handler_class.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
from os.path import exists
55

66
try:
7-
from droid_csv_handler_class import *
7+
from droid_csv_handler_class import GenericCSVHandler
88
except ModuleNotFoundError:
99
try:
10-
from src.anz_rosetta_csv.droid_csv_handler_class import *
10+
from src.anz_rosetta_csv.droid_csv_handler_class import GenericCSVHandler
1111
except ModuleNotFoundError:
12-
from anz_rosetta_csv.droid_csv_handler_class import *
12+
from anz_rosetta_csv.droid_csv_handler_class import GenericCSVHandler
1313

1414
logger = logging.getLogger(__name__)
1515

1616

17-
class provenanceCSVHandler:
18-
# TODO: Better error handling? Format error handling? Validation?
17+
class ProvenanceCSVHandler:
18+
"""Provenance CSV handler class."""
19+
1920
provheaders = ["RECORDNUMBER", "NOTEDATE", "NOTETEXT"]
2021

21-
def readProvenanceCSV(self, provcsvname):
22+
def read_provenance_csv(self, provcsvname):
23+
"""Read provenance CSV and return it to the caller."""
2224
exportlist = None
2325
if not exists(provcsvname):
2426
logger.error(

src/anz_rosetta_csv/rosetta_csv_generator.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99
import json_table_schema
1010
from droid_csv_handler_class import *
1111
from import_sheet_generator import ImportSheetGenerator
12-
from provenance_csv_handler_class import *
12+
from provenance_csv_handler_class import ProvenanceCSVHandler
1313
from rosetta_csv_sections_class import RosettaCSVSections
1414
except ModuleNotFoundError:
1515
try:
1616
from src.anz_rosetta_csv.droid_csv_handler_class import *
1717
from src.anz_rosetta_csv.import_sheet_generator import ImportSheetGenerator
1818
from src.anz_rosetta_csv.json_table_schema import json_table_schema
19-
from src.anz_rosetta_csv.provenance_csv_handler_class import *
19+
from src.anz_rosetta_csv.provenance_csv_handler_class import (
20+
ProvenanceCSVHandler,
21+
)
2022
from src.anz_rosetta_csv.rosetta_csv_sections_class import RosettaCSVSections
2123
except ModuleNotFoundError:
2224
from anz_rosetta_csv.droid_csv_handler_class import *
2325
from anz_rosetta_csv.import_sheet_generator import ImportSheetGenerator
2426
from anz_rosetta_csv.json_table_schema import json_table_schema
25-
from anz_rosetta_csv.provenance_csv_handler_class import *
27+
from anz_rosetta_csv.provenance_csv_handler_class import ProvenanceCSVHandler
2628
from anz_rosetta_csv.rosetta_csv_sections_class import RosettaCSVSections
2729

2830
logger = logging.getLogger(__name__)
@@ -117,8 +119,10 @@ def add_csv_value(self, value):
117119
return field
118120

119121
def readRosettaSchema(self):
120-
f = open(self.rosettaschema, "rb")
121-
importschemajson = f.read()
122+
"""Read the Rosetta Schema File."""
123+
importschemajson = None
124+
with open(self.rosettaschema, "r", encoding="utf-8") as rosetta_schema:
125+
importschemajson = rosetta_schema.read()
122126
importschema = json_table_schema.JSONTableSchema(importschemajson)
123127

124128
importschemadict = importschema.as_dict()
@@ -128,7 +132,6 @@ def readRosettaSchema(self):
128132
importschemaheader + "\n"
129133
) # TODO: Add newline in JSON Handler class?
130134
self.rosettacsvdict = importschemadict["fields"]
131-
f.close()
132135

133136
def createcolumns(self, columno):
134137
columns = ""
@@ -223,10 +226,6 @@ def csvstringoutput(self, csvlist):
223226

224227
csvrows = csvrows + "".join(SIPROW).rstrip(",") + "\n"
225228

226-
# write utf-8 BOM
227-
# NOTE: Don't write UTF-8 BOM... Rosetta doesn't like this.
228-
# sys.stdout.write(u'\uFEFF'.encode('utf-8'))
229-
230229
for sectionrows in csvlist:
231230
rowdata = ""
232231
for sectionrow in sectionrows:
@@ -408,8 +407,8 @@ def create_rosetta_csv(self):
408407

409408
return self.csvstringoutput(fields)
410409

411-
# TODO: unit tests for this...
412410
def listduplicates(self):
411+
"""List duplicates discovered running this script."""
413412
seen = []
414413
dupe = []
415414
for row in self.droidlist:
@@ -420,8 +419,10 @@ def listduplicates(self):
420419
cs = row["SHA1_HASH"]
421420
elif "SHA256_HASH" in row:
422421
cs = row["SHA256_HASH"]
422+
elif "SHA512_HASH" in row:
423+
cs = row["SHA512_HASH"]
423424
else:
424-
sys.stderr.write("No hash available to use in DROID export.\n")
425+
logging.error("no hash available to use in DROID export")
425426
sys.exit(1)
426427
if cs not in seen:
427428
seen.append(cs)
@@ -449,8 +450,8 @@ def export2rosettacsv(self):
449450
# self.readRosettaSchema() #NOTE: Moved to constructor... TODO: Refactor
450451

451452
if self.prov is True:
452-
provhandler = provenanceCSVHandler()
453-
self.provlist = provhandler.readProvenanceCSV(self.provfile)
453+
provhandler = ProvenanceCSVHandler()
454+
self.provlist = provhandler.read_provenance_csv(self.provfile)
454455
if self.provlist is None:
455456
self.prov = False
456457

src/anz_rosetta_csv/rosetta_csv_sections_class.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import configparser as ConfigParser
44
import logging
5+
import sys
56

67
logger = logging.getLogger(__name__)
78

@@ -30,6 +31,5 @@ def __init__(self, configfile):
3031
sectiondict[section] = fieldlist.split(",")
3132
self.sections.append(sectiondict)
3233
else:
33-
sys.stdout.write("Error reading fields from config file, exiting...")
34-
sys.exit(1) # poor-form exiting from a child class?
35-
break
34+
logging.error("error reading fields from config file, exiting...")
35+
sys.exit(1)

tests/test_import_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Archives NZ import generator tests."""
22

3+
# pylint: disable=C0103
4+
35
from typing import Final
46

57
from src.anz_rosetta_csv.rosetta_csv_generator import RosettaCSVGenerator
@@ -639,7 +641,6 @@ def test_duplicates(tmp_path):
639641
schema_file = tmp_dir / "schema.json"
640642
droid_report = tmp_dir / "droid.csv"
641643
list_control_file = tmp_dir / "lc.csv"
642-
tmp_dir / "prov.notes"
643644

644645
config_file.write_text(dupe_config.strip().lstrip())
645646
schema_file.write_text(schema.strip().lstrip())

0 commit comments

Comments
 (0)