|
|
@@ -7,6 +7,7 @@ import re
|
|
|
|
|
|
from path import Path
|
|
|
|
|
|
+
|
|
|
objects = []
|
|
|
|
|
|
|
|
|
@@ -34,6 +35,8 @@ class InvalidFileExt(IOError):
|
|
|
class AccessObject():
|
|
|
type_ = "<unknown>"
|
|
|
_valid_file_exts = (".bas")
|
|
|
+ _re_w_sep = """^|\s|\[|\]|&|\(|\)|\.|!|"|'"""
|
|
|
+
|
|
|
def __init__(self, nom):
|
|
|
self.nom = nom
|
|
|
self.functions = []
|
|
|
@@ -49,7 +52,7 @@ class AccessObject():
|
|
|
def from_file(cls, file):
|
|
|
file = Path(file)
|
|
|
if file.ext not in cls._valid_file_exts:
|
|
|
- raise InvalidFileExt("Format de fichier d'entée non valide ({})".format(file.name))
|
|
|
+ raise InvalidFileExt("Format de fichier d'entrée non valide ({})".format(file.name))
|
|
|
obj = cls(AccessObject.path_to_name(file))
|
|
|
obj.sourcefile = file
|
|
|
obj._sourcecode = file.text()
|
|
|
@@ -77,6 +80,12 @@ class AccessObject():
|
|
|
name_ = name_.replace("[{}]".format(ascii_code), char)
|
|
|
return name_
|
|
|
|
|
|
+ def search_me_regex(self):
|
|
|
+ return re.compile(r"""({sep}){nom}({sep})""".format(p=self._re_w_sep, nom=self.nom))
|
|
|
+
|
|
|
+ def rawsearch_me_regex(self):
|
|
|
+ return self.search_me_regex()
|
|
|
+
|
|
|
class TableObject(AccessObject):
|
|
|
type_ = "Table"
|
|
|
_valid_file_exts = (".xml", ".lnkd")
|
|
|
@@ -114,6 +123,7 @@ DEPS_AND_REFS = 3
|
|
|
class Analyse():
|
|
|
objects = []
|
|
|
duplicated_names = []
|
|
|
+ RAW_SEARCH = False
|
|
|
|
|
|
@staticmethod
|
|
|
def report(current, total, msg=""):
|
|
|
@@ -131,6 +141,9 @@ class Analyse():
|
|
|
|
|
|
@staticmethod
|
|
|
def containsRefsTo(source, target):
|
|
|
+ if Analyse.RAW_SEARCH:
|
|
|
+ rx = target.rawsearch_me_regex()
|
|
|
+ return rx.search(source.sourcecode)
|
|
|
|
|
|
if type(target) is ModuleObject: # L'objet peut contenir des references aux fonctions de l'objet module
|
|
|
for fname in target.functions:
|
|
|
@@ -181,18 +194,12 @@ class Analyse():
|
|
|
for candidate in cls.objects[:index] + cls.objects[index + 1:]:
|
|
|
|
|
|
if Analyse.containsRefsTo(subject, candidate):
|
|
|
+
|
|
|
if mode in (DEPS_AND_REFS, DEPS_ONLY):
|
|
|
subject.add_dep(candidate)
|
|
|
+
|
|
|
if mode in (DEPS_AND_REFS, REFS_ONLY):
|
|
|
candidate.add_ref(subject)
|
|
|
-#
|
|
|
-# for fname in candidate.functions:
|
|
|
-# if Analyse.lookFor(fname, source):
|
|
|
-# if mode in (DEPS_AND_REFS, DEPS_ONLY):
|
|
|
-# subject.add_dep(candidate)
|
|
|
-# if mode in (DEPS_AND_REFS, REFS_ONLY):
|
|
|
-# candidate.add_ref(subject)
|
|
|
-# break
|
|
|
|
|
|
cls.report(total, total, "Analyse terminée")
|
|
|
cls.ended()
|
|
|
@@ -204,7 +211,8 @@ if __name__ == "__main__":
|
|
|
source_dir = Path(r"c:\dev\access\Analytique\source")
|
|
|
|
|
|
here = Path(__file__).parent.abspath()
|
|
|
- datafile = here / "access_data.txt"
|
|
|
+ source_dir = here / "source"
|
|
|
+ datafile = here / "access_analyser.txt"
|
|
|
datafile.remove_p()
|
|
|
|
|
|
def main_report(*_, msg=""):
|
|
|
@@ -215,8 +223,10 @@ if __name__ == "__main__":
|
|
|
|
|
|
with open("data.txt", "w+") as f:
|
|
|
for o in Analyse.objects:
|
|
|
- f.write("* {} - {}{}\n\tdeps > {}\n".format(o.type_,
|
|
|
- o.nom,
|
|
|
- "\n\tfunctions > ".format(", ".join(o.functions)) if o.functions else "",
|
|
|
- o.deps))
|
|
|
+ msg = "# {}: '{}'".format(o.type_, o.nom)
|
|
|
+ msg += "\n\t Utilise: {}".format(", ".join(["'{}'".format(d) for d in o.deps]))
|
|
|
+ msg += "\n\t Est utilisé par: {}".format(", ".join(["'{}'".format(d) for d in o.refs]))
|
|
|
+ msg += "\n"
|
|
|
+ f.write(msg)
|
|
|
+
|
|
|
print("# Terminé")
|