Skip to content

Commit 370ca0c

Browse files
author
Shakeel Mohamed
committed
Updated setup; moved spl generation into dist command.
1 parent dd9d266 commit 370ca0c

File tree

1 file changed

+46
-37
lines changed

1 file changed

+46
-37
lines changed

setup.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -75,53 +75,64 @@ def get_python_files(files):
7575

7676
return python_files
7777

78-
def setup_examples():
79-
"""Function to create .spl files for modular input examples"""
80-
app_names = ["random_numbers", "github_forks"]
81-
82-
splunklib_dir = "splunklib"
83-
modinput_dir = os.path.join(splunklib_dir, "modularinput")
84-
85-
for app in app_names:
86-
spl = tarfile.open(os.path.join("build", app + ".spl"), "w")
87-
88-
spl.add(
89-
os.path.join("examples", app, app + ".py"),
90-
arcname=os.path.join(app, "bin", app + ".py")
91-
)
92-
93-
spl.add(
94-
os.path.join("examples", app, "default", "app.conf"),
95-
arcname=os.path.join(app, "default", "app.conf")
96-
)
97-
spl.add(
98-
os.path.join("examples", app, "README", "inputs.conf.spec"),
99-
arcname=os.path.join(app, "README", "inputs.conf.spec")
100-
)
101-
102-
splunklib_files = get_python_files(os.listdir(splunklib_dir))
103-
for file_name in splunklib_files:
78+
class DistCommand(Command):
79+
"""setup.py command to create .spl files for modular input examples"""
80+
description = "Build modular input example .spl files."
81+
user_options = []
82+
83+
def initialize_options(self):
84+
pass
85+
86+
def finalize_options(self):
87+
pass
88+
89+
def run(self):
90+
app_names = ["random_numbers", "github_forks"]
91+
92+
splunklib_dir = "splunklib"
93+
modinput_dir = os.path.join(splunklib_dir, "modularinput")
94+
95+
for app in app_names:
96+
spl = tarfile.open(os.path.join("build", app + ".spl"), "w")
97+
10498
spl.add(
105-
os.path.join(splunklib_dir, file_name),
106-
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")
107101
)
108102

109-
modinput_files = get_python_files(os.listdir(modinput_dir))
110-
for file_name in modinput_files:
111103
spl.add(
112-
os.path.join(modinput_dir, file_name),
113-
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")
114110
)
115111

116-
spl.close()
112+
splunklib_files = 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 = 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()
117127

118128
setup(
119129
author="Splunk, Inc.",
120130

121131
author_email="devinfo@splunk.com",
122132

123133
cmdclass={'coverage': CoverageCommand,
124-
'test': TestCommand},
134+
'test': TestCommand,
135+
'dist': DistCommand},
125136

126137
description="The Splunk Software Development Kit for Python.",
127138

@@ -145,6 +156,4 @@ def setup_examples():
145156
"Topic :: Software Development :: Libraries :: Python Modules",
146157
"Topic :: Software Development :: Libraries :: Application Frameworks",
147158
],
148-
)
149-
150-
setup_examples()
159+
)

0 commit comments

Comments
 (0)