From 5e8279e84a076964fa764f6b76f5e8728a6c87f7 Mon Sep 17 00:00:00 2001
From: Fawzi Mohamed <fawzi.mohamed@fhi-berlin.mpg.de>
Date: Wed, 22 Jun 2016 04:14:44 +0200
Subject: [PATCH] update sample parser

---
 .gitignore                            | 54 +++++++++++++++++++++++++++
 parser/sample-parser/sample_parser.py | 20 +++++++++-
 2 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a6cb8b6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,54 @@
+# use glob syntax.
+syntax: glob
+*.ser
+*.class
+*~
+*.bak
+#*.off
+*.old
+*.pyc
+*.bk
+*.swp
+.DS_Store
+
+# logging files
+detailed.log
+
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+.scala_dependencies
+
+# idea
+.idea
+*.iml
+
+# building
+target
+build
+null
+tmp*
+temp*
+dist
+test-output
+build.log
+
+# other scm
+.svn
+.CVS
+.hg*
+
+# switch to regexp syntax.
+#  syntax: regexp
+#  ^\.pc/
+
+#SHITTY output not in target directory
+build.log
+
+#emacs TAGS
+TAGS
+
+lib/
+env/
diff --git a/parser/sample-parser/sample_parser.py b/parser/sample-parser/sample_parser.py
index 0795d0d..d21c238 100644
--- a/parser/sample-parser/sample_parser.py
+++ b/parser/sample-parser/sample_parser.py
@@ -1,8 +1,25 @@
+from builtins import object
 import setup_paths
 from nomadcore.simple_parser import SimpleMatcher, mainFunction
 from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
 import os, sys, json
 
+class SampleContext(object):
+    """context for the sample parser"""
+
+    def __init__(self):
+        self.parser = None
+
+    def initialize_values(self):
+        """allows to reset values if the same superContext is used to parse different files"""
+        pass
+
+    def startedParsing(self, path, parser):
+        """called when parsing starts"""
+        self.parser = parser
+        # allows to reset values if the same superContext is used to parse different files
+        self.initialize_values()
+
 # description of the input
 mainFileDescription = SimpleMatcher(name = 'root',
               weak = True,
@@ -31,4 +48,5 @@ metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__f
 metaInfoEnv, warnings = loadJsonFile(filePath = metaInfoPath, dependencyLoader = None, extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
 
 if __name__ == "__main__":
-    mainFunction(mainFileDescription, metaInfoEnv, parserInfo)
+    superContext = SampleContext()
+    mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext = superContext)
-- 
GitLab