Skip to content

Commit

Permalink
adding-function-which-copies-header
Browse files Browse the repository at this point in the history
  • Loading branch information
monishshah-crest authored Nov 27, 2020
1 parent ae75598 commit 15e6204
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import os, time
import re
import glob
from os import system
import shutil
Expand Down Expand Up @@ -687,7 +688,30 @@ def main():

with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "w") as manifest_file:
manifest_file.write(json.dumps(manifest, indent=4, sort_keys=True))


config_file = os.path.join(outputdir, ta_name,'default', "app.conf")
def save_comments(config_file):
"""Save index and content of comments in config file and return dictionary thereof"""
comment_map = {}
with open(config_file, 'r') as file:
i = 0
lines = file.readlines()
for line in lines:
if re.match( r'^\s*#.*?$', line):
comment_map[i] = line
i += 1
return comment_map

def restore_comments(config_file, comment_map):
"""Write comments to config file at their original indices"""
with open(config_file, 'r') as file:
lines = file.readlines()
for (index, comment) in sorted(comment_map.items()):
lines.insert(index, comment)
with open(config_file, 'w') as file:
file.write(''.join(lines))

comment_map = save_comments(config_file)
app_config = configparser.ConfigParser()
app_config.read_file(open(os.path.join(outputdir, ta_name,'default', "app.conf")))
if not 'launcher' in app_config:
Expand All @@ -713,7 +737,8 @@ def main():

with open(os.path.join(outputdir, ta_name,'default', "app.conf"), 'w') as configfile:
app_config.write(configfile)

restore_comments(config_file, comment_map)

#Copy Licenses
license_dir = os.path.abspath(os.path.join(args.source, PARENT_DIR, "LICENSES"))

Expand Down

0 comments on commit 15e6204

Please sign in to comment.