Skip to content

Commit c732830

Browse files
author
Shakeel Mohamed
committed
Setup script now creates spl files in build directory
Also updated __init__.py to allow for the following import style: from splunklib.modularinput import *
1 parent 0740a2a commit c732830

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

setup.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# under the License.
1616

1717
from distutils.core import setup, Command
18-
import os, shutil
18+
import os, shutil, tarfile
1919
import splunklib
2020

2121
def run_test_suite():
@@ -66,6 +66,55 @@ 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+
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:
104+
spl.add(
105+
os.path.join(splunklib_dir, file_name),
106+
arcname=os.path.join(app, "bin", splunklib_dir, file_name)
107+
)
108+
109+
modinput_files = get_python_files(os.listdir(modinput_dir))
110+
for file_name in modinput_files:
111+
spl.add(
112+
os.path.join(modinput_dir, file_name),
113+
arcname=os.path.join(app, "bin", modinput_dir, file_name)
114+
)
115+
116+
spl.close()
117+
69118
setup(
70119
author="Splunk, Inc.",
71120

@@ -98,4 +147,4 @@ def run(self):
98147
],
99148
)
100149

101-
150+
setup_examples()

splunklib/modularinput/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from argument import Argument
2+
from event import Event
3+
from event_writer import EventWriter
4+
from input_definition import InputDefinition
5+
from scheme import Scheme
6+
from script import Script
7+
from validation_definition import ValidationDefinition

0 commit comments

Comments
 (0)