Skip to content

Commit 98afc11

Browse files
author
Shakeel Mohamed
committed
Move get_python_files into DistCommand class; done with modular input code & examples!
1 parent 370ca0c commit 98afc11

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

setup.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ def finalize_options(self):
6666
def run(self):
6767
run_test_suite()
6868

69-
def get_python_files(files):
70-
"""Utility function to get .py files from a list"""
71-
python_files = []
72-
for file_name in files:
73-
if file_name.endswith(".py"):
74-
python_files.append(file_name)
75-
76-
return python_files
77-
7869
class DistCommand(Command):
7970
"""setup.py command to create .spl files for modular input examples"""
8071
description = "Build modular input example .spl files."
@@ -86,44 +77,53 @@ def initialize_options(self):
8677
def finalize_options(self):
8778
pass
8879

80+
@staticmethod
81+
def get_python_files(files):
82+
"""Utility function to get .py files from a list"""
83+
python_files = []
84+
for file_name in files:
85+
if file_name.endswith(".py"):
86+
python_files.append(file_name)
87+
88+
return python_files
89+
8990
def run(self):
9091
app_names = ["random_numbers", "github_forks"]
9192

9293
splunklib_dir = "splunklib"
9394
modinput_dir = os.path.join(splunklib_dir, "modularinput")
9495

9596
for app in app_names:
96-
spl = tarfile.open(os.path.join("build", app + ".spl"), "w")
97-
98-
spl.add(
99-
os.path.join("examples", app, app + ".py"),
100-
arcname=os.path.join(app, "bin", app + ".py")
101-
)
102-
103-
spl.add(
104-
os.path.join("examples", app, "default", "app.conf"),
105-
arcname=os.path.join(app, "default", "app.conf")
106-
)
107-
spl.add(
108-
os.path.join("examples", app, "README", "inputs.conf.spec"),
109-
arcname=os.path.join(app, "README", "inputs.conf.spec")
110-
)
111-
112-
splunklib_files = get_python_files(os.listdir(splunklib_dir))
113-
for file_name in splunklib_files:
97+
with tarfile.open(os.path.join("build", app + ".spl"), "w") as spl:
11498
spl.add(
115-
os.path.join(splunklib_dir, file_name),
116-
arcname=os.path.join(app, "bin", splunklib_dir, file_name)
99+
os.path.join("examples", app, app + ".py"),
100+
arcname=os.path.join(app, "bin", app + ".py")
117101
)
118102

119-
modinput_files = get_python_files(os.listdir(modinput_dir))
120-
for file_name in modinput_files:
121103
spl.add(
122-
os.path.join(modinput_dir, file_name),
123-
arcname=os.path.join(app, "bin", modinput_dir, file_name)
104+
os.path.join("examples", app, "default", "app.conf"),
105+
arcname=os.path.join(app, "default", "app.conf")
106+
)
107+
spl.add(
108+
os.path.join("examples", app, "README", "inputs.conf.spec"),
109+
arcname=os.path.join(app, "README", "inputs.conf.spec")
124110
)
125111

126-
spl.close()
112+
splunklib_files = self.get_python_files(os.listdir(splunklib_dir))
113+
for file_name in splunklib_files:
114+
spl.add(
115+
os.path.join(splunklib_dir, file_name),
116+
arcname=os.path.join(app, "bin", splunklib_dir, file_name)
117+
)
118+
119+
modinput_files = self.get_python_files(os.listdir(modinput_dir))
120+
for file_name in modinput_files:
121+
spl.add(
122+
os.path.join(modinput_dir, file_name),
123+
arcname=os.path.join(app, "bin", modinput_dir, file_name)
124+
)
125+
126+
spl.close()
127127

128128
setup(
129129
author="Splunk, Inc.",

0 commit comments

Comments
 (0)