Skip to content

Instantly share code, notes, and snippets.

@teopost
Last active April 15, 2018 16:30
Show Gist options
  • Save teopost/2b53ccd881f712dcb9f119ed43a2a3c1 to your computer and use it in GitHub Desktop.
Save teopost/2b53ccd881f712dcb9f119ed43a2a3c1 to your computer and use it in GitHub Desktop.
import glob
import ConfigParser, io
import StringIO
import re
BEGIN_TAG="BEGIN METADATA"
END_TAG="END METADATA"
#script_list=glob.glob("*.sh")
script_list=glob.glob("Daily_catalogue_extraction.sh")
sample = """
[metadata]
Author = Stefano Teodorani
Issue = RB-24891
Type = Email
Name = PROD|US&UK|Daily catalogue extraction
Recipients = [email protected], b.mail.com
Source = https://bitbucket.org/acme
"""
for file in script_list:
with open(file) as f:
sample_config = f.read()
match = re.search(BEGIN_TAG+"(.*)"+END_TAG, sample_config, re.MULTILINE|re.DOTALL)
if match:
sample_config = match.group(0)
sample_config = sample_config.replace("# ","")
sample_config = sample_config.replace("#","")
sample_config = sample_config.replace(BEGIN_TAG,"[metadata]")
sample_config = sample_config.replace(END_TAG,"")
config = ConfigParser.RawConfigParser(allow_no_value=True)
config.readfp(StringIO.StringIO(sample_config))
print config.get("metadata", "Author")
print config.get("metadata", "Issue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment