Commit 80587fd9 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Moved package one level deeper, can't use mainFunction anymore so next creating my own...

parent a3c66ab1
import re
import logging
import parsercp2k.setup_paths
from parsercp2k.utils.baseclasses import Parser
from parsercp2k.parsing.implementations import *
from cp2kparser.utils.baseclasses import Parser
from cp2kparser.parsing.implementations import *
logger = logging.getLogger(__name__)
......@@ -71,10 +70,3 @@ class CP2KParser(Parser):
the nomadtoolkit.
"""
return "cp2k.nomadmetainfo.json"
#===============================================================================
# This is what gets run when the scala layer calls for this parser
if __name__ == "__main__":
cp2kparser = CP2KParser()
cp2kparser.scala_main_function()
"""
This is the access point to the parser for the scala layer in the nomad project.
"""
import os
from cp2kparser import CP2KParser
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.simple_parser import mainFunction
# This is what gets run when the scala layer calls for this parser. Currently
# only the outputparser is used because the scala layer doesn't support
# auxiliary files. Also the version identification is skipped and the structure
# used in CP2K 2.6.2 is assumed.
if __name__ == "__main__":
cp2kparser = CP2KParser()
# Get the outputparser class
outputparser = globals()["CP2KOutputParser{}".format("262")](None, None)
# Setup the metainfos
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/{}".format(cp2kparser.get_metainfo_filename())))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)
# Parser info
parserInfo = {'name': 'cp2k-parser', 'version': '1.0'}
# Adjust caching of metadata
cachingLevelForMetaName = outputparser.cachingLevelForMetaName
# Supercontext is where the objet where the callback functions for
# section closing are found
superContext = outputparser
# Main file description is the SimpleParser tree
mainFileDescription = outputparser.outputstructure
# Use the main function from nomadcore
mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext=superContext, cachingLevelForMetaName=cachingLevelForMetaName, onClose={})
......@@ -3,11 +3,8 @@ import sys
import logging
import StringIO
from abc import ABCMeta, abstractmethod
from parsercp2k.parsing.outputparsing import *
from nomadcore.simple_parser import SimpleParserBuilder, defaultParseFile, extractOnCloseTriggers
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.caching_backend import CachingLevel, ActiveBackend
from nomadcore.simple_parser import mainFunction
logger = logging.getLogger(__name__)
......@@ -16,8 +13,11 @@ class Parser(object):
"""A base class for nomad parsers.
Attributes:
self.implementation: an object that actually does the parsing and is
implementation: an object that actually does the parsing and is
setup by this class based on the given contents.
parser_context: A wrapper class for all the parser related information.
This is contructed here and then passed onto the different
implementations.
"""
__metaclass__ = ABCMeta
parser_name = None
......@@ -97,39 +97,12 @@ class Parser(object):
logger.error("No parser implementation has been setup.")
# Write the starting bracket
self.backend.fileOut.write("[")
self.implementation.backend.fileOut.write("[")
self.implementation.parse()
# Write the ending bracket
self.backend.fileOut.write("]\n")
def scala_main_function(self):
"""This function gets called when the scala calls for a parser.
"""
# Get the outputparser class
outputparser = globals()["CP2KOutputParser{}".format("262")](None, None)
# Setup the metainfos
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../nomad-meta-info/meta_info/nomad_meta_info/{}".format(self.get_metainfo_filename())))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)
# Parser info
parserInfo = {'name': 'cp2k-parser', 'version': '1.0'}
# Adjust caching of metadata
cachingLevelForMetaName = outputparser.cachingLevelForMetaName
# Supercontext is where the objet where the callback functions for
# section closing are found
superContext = outputparser
# Main file description is the SimpleParser tree
mainFileDescription = outputparser.outputstructure
# Use the main function from nomadcore
mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext=superContext, cachingLevelForMetaName=cachingLevelForMetaName, onClose={})
self.implementation.backend.fileOut.write("]\n")
#===============================================================================
......
......@@ -5,7 +5,7 @@ from setuptools import setup, find_packages
def main():
# Start package setup
setup(
name="parsercp2k",
name="cp2karser",
version="0.1",
include_package_data=True,
package_data={
......@@ -15,7 +15,7 @@ def main():
author="Lauri Himanen",
author_email="lauri.himanen@gmail.com",
license="GPL3",
packages=["parsercp2k"],
packages=["cp2kparser"],
install_requires=[
'pint',
'numpy',
......
import parsercp2k.utils.logconfig
from parsercp2k.parser import CP2KParser
import sys
import os
import cStringIO
from parsercp2k.implementation.cp2kparserversioner import CP2KParserVersioner
from parsercp2k.generics.testing import get_parser
#===============================================================================
def parse_path(path, metainfo_to_keep=[], metainfo_to_skip=[], dump=False):
"""Generates a cp2k parser using the tools defined in testing.py and parses
the contents in the given path
"""
# If a dump is requested, the results will be saved to a file under the
# current folder
if dump:
stream = cStringIO.StringIO()
else:
stream = sys.stdout
parserbuilder = CP2KParserVersioner
metainfopath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../nomad-meta-info/meta_info/nomad_meta_info/cp2k.nomadmetainfo.json"))
parser = get_parser(path, metainfopath, parserbuilder, metainfo_to_keep, metainfo_to_skip, stream)
parser.parse()
if dump:
outputfile = open(path + "/parseroutput.json", "w")
outputfile.write(stream.getvalue())
import sys
import os
baseDir = os.path.dirname(os.path.abspath(__file__))
commonDir = os.path.normpath(os.path.join(baseDir, "../../../../python-common/common/python"))
if os.path.exists(commonDir):
if not commonDir in sys.path:
sys.path.insert(0, commonDir)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment