Mod: few changes with imports
This commit is contained in:
parent
4dd74591fc
commit
4efb13954c
@ -10,4 +10,4 @@ __version__ = "1.1.0"
|
|||||||
__author__ = __maintainer = "George Kusayko"
|
__author__ = __maintainer = "George Kusayko"
|
||||||
__email__ = "gkusayko@gmail.com"
|
__email__ = "gkusayko@gmail.com"
|
||||||
|
|
||||||
from anisotropy.core.main import main
|
#from anisotropy.core.main import main
|
||||||
|
@ -15,12 +15,12 @@ from anisotropy.core.utils import struct, deepupdate
|
|||||||
# Environment variables and config
|
# Environment variables and config
|
||||||
##
|
##
|
||||||
env = { "ROOT": os.path.abspath(".") }
|
env = { "ROOT": os.path.abspath(".") }
|
||||||
env.update(dict(
|
env.update(
|
||||||
BUILD = os.path.join(env["ROOT"], "build"),
|
BUILD = os.path.join(env["ROOT"], "build"),
|
||||||
LOG = os.path.join(env["ROOT"], "logs"),
|
LOG = os.path.join(env["ROOT"], "logs"),
|
||||||
DEFAULT_CONFIG = os.path.join(env["ROOT"], "anisotropy/config/default.toml"),
|
DEFAULT_CONFIG = os.path.join(env["ROOT"], "anisotropy/config/default.toml"),
|
||||||
CONFIG = os.path.join(env["ROOT"], "conf/config.toml")
|
CONFIG = os.path.join(env["ROOT"], "conf/config.toml")
|
||||||
))
|
)
|
||||||
env["db_path"] = env["BUILD"]
|
env["db_path"] = env["BUILD"]
|
||||||
env["salome_port"] = 2810
|
env["salome_port"] = 2810
|
||||||
|
|
||||||
@ -44,60 +44,20 @@ env["salome_port"] = 2810
|
|||||||
###
|
###
|
||||||
# Logger
|
# Logger
|
||||||
##
|
##
|
||||||
|
from anisotropy.core.utils import setupLogger
|
||||||
logger_env = env.get("logger", {})
|
logger_env = env.get("logger", {})
|
||||||
|
|
||||||
class CustomFormatter(logging.Formatter):
|
|
||||||
grey = "\x1b[38;21m"
|
|
||||||
yellow = "\x1b[33;21m"
|
|
||||||
red = "\x1b[31;21m"
|
|
||||||
bold_red = "\x1b[31;1m"
|
|
||||||
reset = "\x1b[0m"
|
|
||||||
format = logger_env.get("format", "[ %(asctime)s ] [ %(levelname)s ] %(message)s")
|
|
||||||
|
|
||||||
FORMATS = {
|
|
||||||
logging.DEBUG: grey + format + reset,
|
|
||||||
logging.INFO: grey + format + reset,
|
|
||||||
logging.WARNING: yellow + format + reset,
|
|
||||||
logging.ERROR: red + format + reset,
|
|
||||||
logging.CRITICAL: bold_red + format + reset
|
|
||||||
}
|
|
||||||
|
|
||||||
def format(self, record):
|
|
||||||
log_fmt = self.FORMATS.get(record.levelno)
|
|
||||||
formatter = logging.Formatter(log_fmt)
|
|
||||||
|
|
||||||
return formatter.format(record)
|
|
||||||
|
|
||||||
logger = logging.getLogger(logger_env.get("name", "anisotropy"))
|
logger = logging.getLogger(logger_env.get("name", "anisotropy"))
|
||||||
logger.setLevel(logging.INFO)
|
setupLogger(logger, logging.INFO)
|
||||||
|
|
||||||
sh = logging.StreamHandler()
|
|
||||||
sh.setLevel(logging.INFO)
|
|
||||||
sh.setFormatter(CustomFormatter())
|
|
||||||
|
|
||||||
fh = logging.FileHandler(os.path.join(env["LOG"], logger_env.get("name", "anisotropy")))
|
|
||||||
fh.setLevel(logging.DEBUG)
|
|
||||||
fh.setFormatter(CustomFormatter())
|
|
||||||
|
|
||||||
logger.addHandler(sh)
|
|
||||||
logger.addHandler(fh)
|
|
||||||
|
|
||||||
peeweeLogger = logging.getLogger("peewee")
|
peeweeLogger = logging.getLogger("peewee")
|
||||||
peeweeLogger.setLevel(logging.INFO)
|
peeweeLogger.setLevel(logging.INFO)
|
||||||
|
|
||||||
def timer(func):
|
from anisotropy.core.utils import timer
|
||||||
def inner(*args, **kwargs):
|
|
||||||
start = time.monotonic()
|
|
||||||
ret = func(*args, **kwargs)
|
|
||||||
elapsed = time.monotonic() - start
|
|
||||||
|
|
||||||
return ret, elapsed
|
|
||||||
|
|
||||||
return inner
|
|
||||||
|
|
||||||
from anisotropy import __version__
|
from anisotropy import __version__
|
||||||
from anisotropy import salomepl
|
from anisotropy import salomepl
|
||||||
from anisotropy import openfoam
|
from anisotropy import openfoam
|
||||||
|
from anisotropy.samples import Simple, FaceCentered, BodyCentered
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
from peewee import JOIN
|
from peewee import JOIN
|
||||||
|
|
||||||
|
@ -2,7 +2,48 @@ import logging
|
|||||||
|
|
||||||
from multiprocessing import Queue, Process, cpu_count
|
from multiprocessing import Queue, Process, cpu_count
|
||||||
import socket
|
import socket
|
||||||
|
import copy
|
||||||
|
import time
|
||||||
|
from types import FunctionType
|
||||||
|
import os
|
||||||
|
|
||||||
|
class CustomFormatter(logging.Formatter):
|
||||||
|
grey = "\x1b[38;21m"
|
||||||
|
yellow = "\x1b[33;21m"
|
||||||
|
red = "\x1b[31;21m"
|
||||||
|
bold_red = "\x1b[31;1m"
|
||||||
|
reset = "\x1b[0m"
|
||||||
|
format = "[ %(asctime)s ] [ %(levelname)s ] %(message)s"
|
||||||
|
|
||||||
|
FORMATS = {
|
||||||
|
logging.DEBUG: grey + format + reset,
|
||||||
|
logging.INFO: grey + format + reset,
|
||||||
|
logging.WARNING: yellow + format + reset,
|
||||||
|
logging.ERROR: red + format + reset,
|
||||||
|
logging.CRITICAL: bold_red + format + reset
|
||||||
|
}
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
log_fmt = self.FORMATS.get(record.levelno)
|
||||||
|
formatter = logging.Formatter(log_fmt)
|
||||||
|
|
||||||
|
return formatter.format(record)
|
||||||
|
|
||||||
|
def setupLogger(logger, level: int):
|
||||||
|
logger.setLevel(level)
|
||||||
|
|
||||||
|
sh = logging.StreamHandler()
|
||||||
|
sh.setLevel(level)
|
||||||
|
sh.setFormatter(CustomFormatter())
|
||||||
|
|
||||||
|
fh = logging.FileHandler(os.path.join("logs", logger.name))
|
||||||
|
fh.setLevel(level)
|
||||||
|
fh.setFormatter(CustomFormatter())
|
||||||
|
|
||||||
|
logger.addHandler(sh)
|
||||||
|
logger.addHandler(fh)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
class struct:
|
class struct:
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -42,7 +83,6 @@ class struct:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
import copy
|
|
||||||
|
|
||||||
def deepupdate(target, src):
|
def deepupdate(target, src):
|
||||||
for k, v in src.items():
|
for k, v in src.items():
|
||||||
@ -64,44 +104,25 @@ def deepupdate(target, src):
|
|||||||
else:
|
else:
|
||||||
target[k] = copy.copy(v)
|
target[k] = copy.copy(v)
|
||||||
|
|
||||||
class Logger:
|
|
||||||
def __init__(self, name, logpath):
|
|
||||||
logging.basicConfig(
|
|
||||||
level = logging.INFO,
|
|
||||||
format = "%(levelname)s: %(message)s",
|
|
||||||
handlers = [
|
|
||||||
logging.StreamHandler(),
|
|
||||||
logging.FileHandler(logpath)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.logger = logging.getLogger(name)
|
|
||||||
self.warnings = 0
|
|
||||||
self.errors = 0
|
|
||||||
self.criticals = 0
|
|
||||||
self.exceptions = 0
|
|
||||||
|
|
||||||
def info(self, *args):
|
def timer(func: FunctionType) -> (tuple, float):
|
||||||
self.logger.info(*args)
|
"""(Decorator) Returns output of inner function and execution time
|
||||||
|
|
||||||
def warning(self, *args):
|
:param func: inner function
|
||||||
self.warnings += 1
|
:type: FunctionType
|
||||||
self.logger.warning(*args)
|
|
||||||
|
|
||||||
def error(self, *args):
|
:return: output, elapsed time
|
||||||
self.errors += 1
|
:rtype: tuple(tuple, float)
|
||||||
self.logger.error(*args)
|
"""
|
||||||
|
def inner(*args, **kwargs):
|
||||||
|
start = time.monotonic()
|
||||||
|
ret = func(*args, **kwargs)
|
||||||
|
elapsed = time.monotonic() - start
|
||||||
|
|
||||||
def critical(self, *args):
|
return ret, elapsed
|
||||||
self.criticals += 1
|
|
||||||
self.logger.critical(*args)
|
|
||||||
|
|
||||||
def exception(self, *args):
|
return inner
|
||||||
self.exceptions += 1
|
|
||||||
self.logger.exception(*args)
|
|
||||||
|
|
||||||
def fancyline(self):
|
|
||||||
self.logger.info("-" * 80)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from anisotropy.samples.simple import Simple
|
||||||
|
from anisotropy.samples.bodyCentered import BodyCentered
|
||||||
|
from anisotropy.samples.faceCentered import FaceCentered
|
@ -1,4 +1,5 @@
|
|||||||
from math import pi, sqrt
|
from math import pi, sqrt
|
||||||
|
from anisotropy.salomepl import geometry
|
||||||
|
|
||||||
class BodyCentered(object):
|
class BodyCentered(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -13,9 +14,8 @@ class BodyCentered(object):
|
|||||||
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
import salomepl
|
|
||||||
|
|
||||||
geompy = salomepl.geometry.getGeom()
|
geompy = geometry.getGeom()
|
||||||
|
|
||||||
###
|
###
|
||||||
# Pore Cell
|
# Pore Cell
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from math import pi, sqrt
|
from math import pi, sqrt
|
||||||
|
from anisotropy.salomepl import geometry
|
||||||
|
|
||||||
class FaceCentered(object):
|
class FaceCentered(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -13,9 +14,8 @@ class FaceCentered(object):
|
|||||||
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
import salomepl
|
|
||||||
|
|
||||||
geompy = salomepl.geometry.getGeom()
|
geompy = geometry.getGeom()
|
||||||
|
|
||||||
###
|
###
|
||||||
# Pore Cell
|
# Pore Cell
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from math import pi, sqrt
|
from math import pi, sqrt
|
||||||
|
from anisotropy.salomepl import geometry
|
||||||
|
|
||||||
class Simple(object):
|
class Simple(object):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -13,9 +14,8 @@ class Simple(object):
|
|||||||
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
import salomepl
|
|
||||||
|
|
||||||
geompy = salomepl.geometry.getGeom()
|
geompy = geometry.getGeom()
|
||||||
|
|
||||||
###
|
###
|
||||||
# Pore Cell
|
# Pore Cell
|
||||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@ -26,6 +26,7 @@ class TestAnisotropy(unittest.TestCase):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
passed = False
|
passed = False
|
||||||
|
print(e)
|
||||||
|
|
||||||
self.assertTrue(passed)
|
self.assertTrue(passed)
|
||||||
|
|
||||||
@ -35,6 +36,10 @@ class TestAnisotropy(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(self.model.params["structure"]["type"], "simple")
|
self.assertEqual(self.model.params["structure"]["type"], "simple")
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
#os.removedirs(self.model.env["BUILD"])
|
||||||
|
#os.removedirs(self.model.env["LOG"])
|
||||||
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user