ldcheck.py

changeset 150
fcc07f6907a8
parent 149
7c01f9876b69
--- a/ldcheck.py	Thu Aug 26 19:43:03 2021 +0300
+++ b/ldcheck.py	Thu Aug 26 19:49:55 2021 +0300
@@ -18,6 +18,9 @@
 import header
 import parse
 
+from os.path import realpath
+script_directory = Path(realpath(__file__)).parent
+
 def check_library_paths(library_paths):
     for library_path in library_paths:
         if not library_path.exists():
@@ -52,10 +55,8 @@
         Contains context-dependant LDraw information, like library directory
         paths and the colour table.
     '''
-    def __init__(self, libraries = None):
+    def __init__(self, libraries):
         self._libraries = libraries
-        if not self._libraries:
-            self._libraries = ldraw_dirs_from_config()
         self.ldconfig_colour_data = self.load_ldconfig_ldr()
         self.check_library_paths()
     @property
@@ -113,14 +114,16 @@
     def is_valid_colour(self, colour):
         return self.is_ldconfig_colour(colour) or colour.is_direct_colour
 
-def parse_commandline_arguments():
+def load_rcfile():
     import os
     rcpath = Path(os.path.expanduser('~/.config/ldcheckrc'))
     if rcpath.exists():
         with rcpath.open() as file:
-            rcargs = ['--' + line.strip() for line in file]
+            return ['--' + line.strip() for line in file]
     else:
-        rcargs = []
+        return []
+
+def parse_commandline_arguments():
     import argparse
     class ListProblemTypesAction(argparse.Action):
         def __init__(self, option_strings, dest, nargs = None, **kwargs):
@@ -170,8 +173,7 @@
             version = version_string,
         ),
     )
-    arglist = rcargs + sys.argv[1:]
-    return parser.parse_args(arglist)
+    return parser.parse_args(load_rcfile() + sys.argv[1:])
 
 def format_report(report, model, test_suite, *, use_colors = True):
     from testsuite import problem_text
@@ -198,6 +200,10 @@
         messages.append(message)
     return '\n'.join(messages)
 
+def postprocess_library_paths(libraries_strings):
+    import os
+    return [Path(os.path.expanduser(library)) for library in libraries_strings]
+
 def main():
     args = parse_commandline_arguments()
     # Make sure that we have at least one library path specified.
@@ -209,7 +215,7 @@
     # Prepare the list of libraries. This also expands the ~ for the home
     # directory
     import os
-    libraries = [Path(os.path.expanduser(library)) for library in args.library]
+    libraries = postprocess_library_paths(args.library)
     check_library_paths(libraries)
     load_ldconfig(libraries)
     try:

mercurial