Skip to content

Commit

Permalink
fixed-indent-and -added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
monishshah-crest authored Nov 28, 2020
1 parent 4631f51 commit 0046f80
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

__version__ = "0.0.0"
__version__ = "4.1.9b1.post4.dev0+ee0b519f"

import logging
import os, time
Expand Down Expand Up @@ -558,33 +558,34 @@ def _removeinput(path):
os.remove(fl)
except OSError:
pass

config_file = os.path.join(outputdir, ta_name,'default', "app.conf")
def save_comments(config_file):

def save_comments(outputdir, ta_name):
"""
Save index and content of comments in config file and return dictionary thereof
Save index and content of comments in conf 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
config_file = os.path.join(outputdir, ta_name,'default', "app.conf")
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):
def restore_comments(outputdir, ta_name, comment_map):
"""
Write comments to config file at their original indices
Write comments to conf file at their original indices
"""
config_file = os.path.join(outputdir, ta_name,'default', "app.conf")
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))

def main():
parser = argparse.ArgumentParser(description="Build the add-on")
parser.add_argument(
Expand Down Expand Up @@ -714,8 +715,8 @@ 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))

comment_map = save_comments(config_file)
comment_map = save_comments(outputdir, ta_name)
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 @@ -741,7 +742,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)
#restore License header
restore_comments(outputdir, ta_name, comment_map)

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

0 comments on commit 0046f80

Please sign in to comment.