patme 0.4.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of patme might be problematic. Click here for more details.

Files changed (46) hide show
  1. patme/__init__.py +52 -0
  2. patme/buildtools/__init__.py +7 -0
  3. patme/buildtools/rce_releasecreator.py +336 -0
  4. patme/buildtools/release.py +26 -0
  5. patme/femtools/__init__.py +5 -0
  6. patme/femtools/abqmsgfilechecker.py +137 -0
  7. patme/femtools/fecall.py +1092 -0
  8. patme/geometry/__init__.py +0 -0
  9. patme/geometry/area.py +124 -0
  10. patme/geometry/coordinatesystem.py +635 -0
  11. patme/geometry/intersect.py +284 -0
  12. patme/geometry/line.py +183 -0
  13. patme/geometry/misc.py +420 -0
  14. patme/geometry/plane.py +464 -0
  15. patme/geometry/rotate.py +244 -0
  16. patme/geometry/scale.py +152 -0
  17. patme/geometry/shape2d.py +50 -0
  18. patme/geometry/transformations.py +1831 -0
  19. patme/geometry/translate.py +139 -0
  20. patme/mechanics/__init__.py +4 -0
  21. patme/mechanics/loads.py +435 -0
  22. patme/mechanics/material.py +1260 -0
  23. patme/service/__init__.py +7 -0
  24. patme/service/decorators.py +85 -0
  25. patme/service/duration.py +96 -0
  26. patme/service/exceptionhook.py +104 -0
  27. patme/service/exceptions.py +36 -0
  28. patme/service/io/__init__.py +3 -0
  29. patme/service/io/basewriter.py +122 -0
  30. patme/service/logger.py +375 -0
  31. patme/service/mathutils.py +108 -0
  32. patme/service/misc.py +71 -0
  33. patme/service/moveimports.py +217 -0
  34. patme/service/stringutils.py +419 -0
  35. patme/service/systemutils.py +290 -0
  36. patme/sshtools/__init__.py +3 -0
  37. patme/sshtools/cara.py +435 -0
  38. patme/sshtools/clustercaller.py +420 -0
  39. patme/sshtools/facluster.py +350 -0
  40. patme/sshtools/sshcall.py +168 -0
  41. patme-0.4.4.dist-info/LICENSE +21 -0
  42. patme-0.4.4.dist-info/LICENSES/MIT.txt +9 -0
  43. patme-0.4.4.dist-info/METADATA +168 -0
  44. patme-0.4.4.dist-info/RECORD +46 -0
  45. patme-0.4.4.dist-info/WHEEL +4 -0
  46. patme-0.4.4.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ The modules of this package support program runs with a logger, exceptions, duration checking etc.
7
+ """
@@ -0,0 +1,85 @@
1
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ Created on 13.07.2016
7
+
8
+ @author: schu_a1
9
+ """
10
+ import cProfile
11
+ import functools
12
+ import hashlib
13
+ import pickle
14
+
15
+ from patme.service.logger import log
16
+
17
+
18
+ def inheritDocStringFromFunction(fromFunction):
19
+ """For the original implementation refer to https://groups.google.com/forum/#!msg/comp.lang.python/HkB1uhDcvdk/lWzWtPy09yYJ"""
20
+
21
+ def docstringInheritingDecorator(toFunction):
22
+ toFunction.__doc__ = fromFunction.__doc__
23
+ return toFunction
24
+
25
+ return docstringInheritingDecorator
26
+
27
+
28
+ def memoize(obj):
29
+ """Caches a function's return value each time it is called.
30
+ If called later with the same arguments, the cached value is returned
31
+ """
32
+ cache = obj.cache = {}
33
+
34
+ @functools.wraps(obj)
35
+ def memoizer(*args, **kwargs):
36
+ # =======================================================================
37
+ # calculate key
38
+ # =======================================================================
39
+ try:
40
+ pickleString = pickle.dumps((args, kwargs), protocol=0)
41
+ key = hashlib.sha256(pickleString).hexdigest()
42
+ except AttributeError: # if items can not be pickled
43
+ try:
44
+ key = args + tuple(kwargs.items())
45
+ hash(key) # try to hash key
46
+ except TypeError: # if args or kwargs can not be hashed
47
+ log.debug("Args and kwargs can not be cached. Calculating function each time.")
48
+ return obj(*args, **kwargs)
49
+ # =======================================================================
50
+ # call function or use cached samples and return them
51
+ # =======================================================================
52
+ if key not in cache:
53
+ cache[key] = obj(*args, **kwargs)
54
+ else:
55
+ log.debug("use cached results for these args and kwargs: {}".format((args, kwargs)))
56
+ return cache[key]
57
+
58
+ return memoizer
59
+
60
+
61
+ def avoidDublicate(obj):
62
+ """Returns None, if this input was already processed"""
63
+ cache = obj.cache = {}
64
+
65
+ @functools.wraps(obj)
66
+ def memoizer(*args, **kwargs):
67
+ key = repr(args) + str(kwargs)
68
+ if key not in cache:
69
+ cache[key] = True
70
+ obj(*args, **kwargs)
71
+ else:
72
+ return
73
+
74
+ return memoizer
75
+
76
+
77
+ def returnNoneOnFail(obj):
78
+ @functools.wraps(obj)
79
+ def returnFunc(*args, **kwargs):
80
+ try:
81
+ return obj(*args, **kwargs)
82
+ except:
83
+ return None
84
+
85
+ return returnFunc
@@ -0,0 +1,96 @@
1
+ # Copyright (C) 2013 Deutsches Zentrum fuer Luft- und Raumfahrt(DLR, German Aerospace Center) <www.dlr.de>
2
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ """
7
+ Measurement of the duration for executing functions and methods and within methods.
8
+
9
+ Usage for **functions and methods**::
10
+
11
+ from patme.service.duration import Duration
12
+
13
+ duration = Duration()
14
+ @duration.timeit
15
+ def testfunc():
16
+ a='do something'
17
+
18
+ Usage **within functions/methods**::
19
+
20
+ from patme.service.duration import measureDuration
21
+
22
+ def testfunc():
23
+ with measureDuration():
24
+ a='do something'
25
+
26
+ The **logLevel** of all Duration instances may be changed with ``setDurationLogLevel``:
27
+
28
+ >>> from patme.service.logger import log
29
+ >>> from patme.service.duration import setDurationLogLevel
30
+ >>> setDurationLogLevel(log.logLevel + 1)
31
+
32
+
33
+ """
34
+
35
+ import logging
36
+ import time
37
+ from contextlib import contextmanager
38
+
39
+ from patme.service.logger import log
40
+
41
+
42
+ class Duration:
43
+ """
44
+ classdocs
45
+ """
46
+
47
+ def __init__(self):
48
+ """
49
+ Constructor
50
+ """
51
+
52
+ def timeit(self, method):
53
+ global _durationLogLevel
54
+
55
+ def timed(*args, **kw):
56
+ ts = time.time()
57
+ result = method(*args, **kw)
58
+ te = time.time()
59
+ log.log(
60
+ _durationLogLevel,
61
+ f"Duration for execution of method or class {method.__name__!r}: {te - ts:4.4f} sec",
62
+ )
63
+ return result
64
+
65
+ return timed
66
+
67
+
68
+ _durationLogLevel = log.logLevel + 1
69
+ logging.addLevelName(_durationLogLevel, "TIME")
70
+
71
+
72
+ def setDurationLogLevel(logLevel):
73
+ """Sets the log level to the logging module and the Duration class"""
74
+ global _durationLogLevel
75
+ logging.addLevelName(logLevel, "TIME")
76
+ _durationLogLevel = logLevel
77
+
78
+
79
+ def getDurationLogLevel():
80
+ """Returns the duration log level"""
81
+ return _durationLogLevel
82
+
83
+
84
+ @contextmanager
85
+ def measureDuration():
86
+ """doc"""
87
+ start = time.time()
88
+ yield
89
+ end = time.time()
90
+ print("Duration: %2.5f" % (end - start))
91
+
92
+
93
+ if __name__ == "__main__":
94
+ import doctest
95
+
96
+ doctest.testmod(verbose=True)
@@ -0,0 +1,104 @@
1
+ # Copyright (C) 2013 Deutsches Zentrum fuer Luft- und Raumfahrt(DLR, German Aerospace Center) <www.dlr.de>
2
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ """
7
+ In order to have better readable error messages for users, the standard exception output is modified.
8
+
9
+ This exception hook prints the exceptions message in a nice format without traceback. The console output and
10
+ traceback are written to a file. The exception hook is set in place using the redirectExceptions function.
11
+
12
+ Usage::
13
+
14
+ from patme.service.exceptionhook import redirectExceptions
15
+ redirectExceptions(progName='MyProg', ver='0.1.0')
16
+ raise Exception('foobar')
17
+
18
+ Output::
19
+
20
+ ################################################################################
21
+ Error: Program "MyProg" stopped due to an exception
22
+ 2020-05-04, 18:20:49
23
+ Version: 0.1.0
24
+ Error log file at: C:\\eclipse_projects\\patme\\src\\patme\\service\\err.log
25
+ Error message:
26
+ --------------------------------------------------------------------------------
27
+ """
28
+
29
+ import io
30
+ import os
31
+ import sys
32
+ import time
33
+ import traceback
34
+
35
+ from patme.service.logger import log
36
+
37
+ errorLogFilename = None
38
+ programName = None
39
+ version = None
40
+
41
+
42
+ def redirectExceptions(errorLogFile="err.log", toDir=None, progName=None, ver=None):
43
+ """introduces the a nicer exception hook into this python process
44
+
45
+ :param errorLogFile: File containing the exception message including the traceback
46
+ :param toDir: Directory of the error log file.
47
+ :param progName: name of the program
48
+ :param ver: version of the program"""
49
+ if toDir is not None:
50
+ errorLogFile = os.path.join(toDir, os.path.basename(errorLogFile))
51
+
52
+ global errorLogFilename, programName, version
53
+ errorLogFilename = errorLogFile
54
+ programName = progName
55
+ version = ver
56
+
57
+ # set system exception hook
58
+ sys.excepthook = excepthook
59
+
60
+
61
+ def excepthook(excType, excValue, tracebackobj):
62
+ """
63
+ function to catch exceptions. It writes a log to errorLogFilename.
64
+
65
+ :param excType: exception type
66
+ :param excValue: exception value
67
+ :param tracebackobj: traceback object
68
+ """
69
+ separator = "-" * 80
70
+ separatorTop = "#" * 80
71
+
72
+ versionInfo = "" if version is None else "Version: " + version + "\n"
73
+ name = "" if programName is None else ' "' + programName + '"'
74
+ logFileNotice = f"Error log file at: {os.path.abspath(errorLogFilename)}"
75
+ timeString = time.strftime("%Y-%m-%d, %H:%M:%S")
76
+ notice = f"Error: Program{name} stopped due to an exception"
77
+
78
+ tbinfofile = io.StringIO()
79
+ traceback.print_tb(tracebackobj, None, tbinfofile)
80
+ tbinfofile.seek(0)
81
+ tbinfo = "Traceback:\n" + tbinfofile.read()
82
+ errmsg = f"{str(excType)}: \n{str(excValue)}"
83
+ sections = [
84
+ separatorTop,
85
+ notice,
86
+ timeString,
87
+ versionInfo + logFileNotice,
88
+ "Error message:",
89
+ separator,
90
+ errmsg,
91
+ separator,
92
+ tbinfo,
93
+ ]
94
+ msg = "\n".join(sections) + "\n" * 4
95
+ if errorLogFilename:
96
+ try:
97
+ with open(os.path.normpath(errorLogFilename), "a") as f:
98
+ f.write(msg)
99
+ except OSError:
100
+ pass
101
+ log.end()
102
+ sys.stdout.flush()
103
+ sys.stderr.write("\n".join(sections[:8]) + "\n\n")
104
+ sys.stderr.flush()
@@ -0,0 +1,36 @@
1
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ Custom exceptions in order to specialize exception names and to catch tool-specific exceptions only.
7
+ """
8
+
9
+
10
+ class CustomException(Exception):
11
+ """This class defines and abstract exception class so that customized exceptions
12
+ can be inherited."""
13
+
14
+ def __init__(self, value):
15
+ """doc"""
16
+ self.value = value
17
+
18
+ def __str__(self):
19
+ """Returning the error message"""
20
+ return repr(self.value)
21
+
22
+
23
+ class InternalError(CustomException):
24
+ """classdocs"""
25
+
26
+
27
+ class ImproperParameterError(CustomException):
28
+ """classdocs"""
29
+
30
+
31
+ class DelisSshError(CustomException):
32
+ """classdocs"""
33
+
34
+
35
+ class GeometryError(CustomException):
36
+ """classdocs"""
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
2
+ #
3
+ # SPDX-License-Identifier: MIT
@@ -0,0 +1,122 @@
1
+ # Copyright (C) 2013 Deutsches Zentrum fuer Luft- und Raumfahrt(DLR, German Aerospace Center) <www.dlr.de>
2
+ # SPDX-FileCopyrightText: 2022 German Aerospace Center (DLR)
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ """
7
+
8
+ This module contains a generic writer to create arbitrary-based output. All Writers shall
9
+ contain the same public methods.
10
+ """
11
+ import os
12
+ import traceback
13
+ from io import StringIO
14
+
15
+ from patme.service.logger import log
16
+
17
+
18
+ class GenericWriter:
19
+ """Abstract geometry writer class"""
20
+
21
+ commentChar = ""
22
+
23
+ def __init__(self, filename="", **kwargs):
24
+ """doc"""
25
+ self.filename = filename
26
+ self.lineBuffer = StringIO()
27
+
28
+ def __enter__(self):
29
+ """doc"""
30
+ fObj = getattr(self, "f", None)
31
+ logFunction = log.debug
32
+ if not fObj:
33
+ try:
34
+ self.lineBuffer = StringIO()
35
+ mode, descr = ("w", "") if getattr(self, "overwriteFile", True) else ("a", "re")
36
+ logFunction(f"{descr}opening file {self.filename}")
37
+ self.f = open(self.filename, mode)
38
+ except:
39
+ self.close()
40
+ raise
41
+ elif fObj.closed:
42
+ try:
43
+ logFunction(f"reopening file {self.filename}")
44
+ self.lineBuffer = StringIO()
45
+ self.f = open(self.filename, "a")
46
+ except:
47
+ self.close()
48
+ raise
49
+ return self
50
+
51
+ def __exit__(self, exc_type, exc_val, exc_tb):
52
+ """doc"""
53
+ if exc_type:
54
+ traceback.print_exception(exc_type, exc_val, exc_tb)
55
+ else:
56
+ self.end()
57
+
58
+ def preamble(self, *args, **kwargs):
59
+ """Doing writer-dependend initialization work"""
60
+ raise NotImplementedError("This is an abstract method.")
61
+
62
+ def end(self):
63
+ """Writer-dependent finalizing of the writer."""
64
+ raise NotImplementedError("This is an abstract method.")
65
+
66
+ def includeOtherFile(self, otherFile):
67
+ """Writer-dependent including of other files into current writer instance."""
68
+ raise NotImplementedError("This is an abstract method.")
69
+
70
+ def close(self):
71
+ """doc"""
72
+ try:
73
+ # write line buffer content to file
74
+ self.f.write(self.lineBuffer.getvalue())
75
+ except:
76
+ log.debug(f'Filedescriptor of writer "{self}" is not open! Could not write line')
77
+
78
+ if hasattr(self, "f") and not self.f.closed:
79
+ log.debug(f"closing file {self.filename}")
80
+ self.f.close()
81
+
82
+ self.lineBuffer.close() # reset buffer
83
+
84
+ def save(self):
85
+ """Saving the writer output to a writer dependent path."""
86
+ self._save()
87
+
88
+ def functionPreamble(self, functionName="", sketchNumber=""):
89
+ """Writes preamble of a function: like Subroutine ... or function ..."""
90
+
91
+ def commentHeadline(self, comment="", printTime=False):
92
+ """Big comment"""
93
+
94
+ def comment(self, comment=""):
95
+ self.writeRow(self.commentChar + comment)
96
+
97
+ def printTime(self, outString):
98
+ """This method makes the output language print the"""
99
+
100
+ def writeRows(self, rows):
101
+ """doc"""
102
+ self.writeRow("\n".join(rows))
103
+
104
+ def writeRow(self, outString=""):
105
+ """doc"""
106
+ self.lineBuffer.write(outString + "\n")
107
+
108
+ def orientationPoint(self, point):
109
+ """is intended for ansys to write the orientation point of beams
110
+
111
+ Other geometry writer do not need this point, thus this method omits everything
112
+ """
113
+
114
+ def _getRunDir(self):
115
+ """doc"""
116
+ if self.filename:
117
+ pathName = os.path.dirname(os.path.abspath(self.filename))
118
+ if pathName != "":
119
+ return pathName
120
+ return "."
121
+
122
+ runDir = property(fget=_getRunDir)