15
15
# under the License.
16
16
17
17
from distutils .core import setup , Command
18
- import os , shutil
18
+ import os , shutil , tarfile
19
19
import splunklib
20
20
21
21
def run_test_suite ():
@@ -66,6 +66,55 @@ def finalize_options(self):
66
66
def run (self ):
67
67
run_test_suite ()
68
68
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
+
69
118
setup (
70
119
author = "Splunk, Inc." ,
71
120
@@ -98,4 +147,4 @@ def run(self):
98
147
],
99
148
)
100
149
101
-
150
+ setup_examples ()
0 commit comments