@@ -41,14 +41,17 @@ def cli():
4141 'but do not send it' )
4242@click .option ('--template' , '-t' , type = click .File ('r' ), required = True ,
4343 help = 'Template to send.' )
44+ @click .option ('--providers' , '-p' , type = click .File ('r' ), required = False ,
45+ help = 'File with custom providers dict.' )
4446@click .option ('--interactive' , '-i' , is_flag = True ,
4547 help = 'Interactive mode.' )
4648@click .option ('--raw_mode' , '-raw' , is_flag = True ,
4749 help = 'Send raw mode.' )
48- @click .option ('--prob' , default = 100 , help = 'Probability (0-100).' )
49- @click .option ('--freq' , default = "1-1" , help = 'Frequency in seconds. Example:'
50- '"1.0-5.0" = random time '
51- 'between 1 sec. to 5secs.' )
50+ @click .option ('--probability' , default = 100 , help = 'Probability (0-100).' )
51+ @click .option ('--frequency' , default = "(1,1)" , help = 'Frequency in seconds. '
52+ 'Example: '
53+ '"1.0-5.0" = random time '
54+ 'between 1 sec. to 5secs.' )
5255@click .option ('--batch_mode' , is_flag = True ,
5356 help = 'Enable blatch mode, a lot of events will be generated as '
5457 'fast as possible and written to a file. The events will be '
@@ -73,6 +76,18 @@ def cli():
7376def cli (** kwargs ):
7477 """Perform query by query string"""
7578 engine , cfg = configure (kwargs )
79+ providers = None
80+
81+ try :
82+ if "providers" in cfg .keys ():
83+ import importlib
84+
85+ providers_module = importlib .import_module (cfg .get ("providers" ))
86+ providers = providers_module .get_providers ()
87+ except Exception as error :
88+ print_error ("Error when loading Providers" , show_help = False , stop = False )
89+ print_error (error , show_help = False , stop = True )
90+
7691 params = []
7792
7893 click .echo ("» Press Ctrl+C to stop the process «" , file = sys .stderr )
@@ -84,7 +99,9 @@ def cli(**kwargs):
8499 params .append ('Simulation' )
85100 thread = SimulationFakeGenerator (cfg ['template' ],
86101 interactive = cfg ['interactive' ],
87- prob = cfg ['prob' ], freq = cfg ['freq' ])
102+ probability = cfg ['probability' ],
103+ frequency = cfg ['frequency' ],
104+ providers = providers )
88105 elif cfg ['batch_mode' ]:
89106 params .append ('Batch mode' )
90107 start_date = parser .parse (cfg ['date_range' ][0 ])
@@ -93,24 +110,31 @@ def cli(**kwargs):
93110 end_date ),
94111 file = sys .stderr )
95112 thread = BatchFakeGenerator (
96- cfg ['template' ], start_date , end_date , prob = cfg ['prob' ],
97- freq = cfg ['freq' ], date_format = cfg ['date_format' ],
113+ cfg ['template' ], start_date , end_date ,
114+ probability = cfg ['probability' ],
115+ frequency = cfg ['frequency' ],
116+ date_format = cfg ['date_format' ],
98117 dont_remove_microseconds = cfg ['dont_remove_microseconds' ],
99- file_name = cfg .get ('file_name' , None ))
118+ file_name = cfg .get ('file_name' , None ),
119+ providers = providers )
100120 elif cfg ['raw_mode' ]:
101121 scfg = cfg ['sender' ]
102122 params .append ('Host={0}:{1}' .format (scfg .get ('address' , None ),
103123 scfg .get ("port" , None )))
104124 thread = SyslogRawFakeGenerator (engine , cfg .get ('template' , None ),
105125 interactive = cfg ['interactive' ],
106- prob = cfg ['prob' ], freq = cfg ['freq' ],
126+ probability = cfg ['probability' ],
127+ frequency = cfg ['frequency' ],
128+ providers = providers ,
107129 verbose = cfg ['verbose' ])
108130 elif cfg .get ('file_name' , None ):
109131 params .append ('File Name {}' .format (cfg ['file_name' ]))
110132 thread = FileFakeGenerator (cfg ['template' ],
111133 interactive = cfg ['interactive' ],
112- prob = cfg ['prob' ], freq = cfg ['freq' ],
134+ probability = cfg ['probability' ],
135+ frequency = cfg ['frequency' ],
113136 file_name = cfg ['file_name' ],
137+ providers = providers ,
114138 verbose = cfg ['verbose' ])
115139 else :
116140 scfg = cfg ['sender' ]
@@ -124,12 +148,15 @@ def cli(**kwargs):
124148 )
125149 thread = SyslogFakeGenerator (engine , cfg ['template' ],
126150 interactive = cfg ['interactive' ],
127- prob = cfg ['prob' ], freq = cfg ['freq' ],
128- tag = cfg .get ('tag' , "my.app.faker.test" ),
151+ probability = cfg ['probability' ],
152+ frequency = cfg ['frequency' ],
153+ providers = providers ,
154+ tag = cfg .get ("tag" ,
155+ "my.app.faker.test" ),
129156 verbose = cfg ['verbose' ])
130157
131- params .append ('Prob ={0}' .format (cfg ['prob ' ]))
132- params .append ('Freq ={0}' .format (cfg ['freq ' ]))
158+ params .append ('probability ={0}' .format (cfg ['probability ' ]))
159+ params .append ('frequency ={0}' .format (cfg ['frequency ' ]))
133160 click .echo ("» {0} «\n " .format (', ' .join (params )), file = sys .stderr )
134161
135162 thread .daemon = True
@@ -153,18 +180,20 @@ def configure(args):
153180 """For load configuration file/object"""
154181
155182 if args .get ('config' ):
156- config = Configuration (args .get ('config' ))
183+ config = Configuration (path = args .get ('config' ))
157184 config .mix (dict (args ))
158185 else :
159186 config = dict (args )
160187
161- if 'freq' in config .keys ():
162- parts = config ['freq' ].split ('-' )
163- config ['freq' ] = (float (parts [0 ]), float (parts [1 ]))
188+ if 'frequency' in config .keys () and isinstance (config .get ("frequency" ),
189+ (str , bytes )):
190+ config ['frequency' ] = tuple ([float (x )
191+ for x
192+ in config .get ("frequency" ).split ("-" )])
164193
165194 config ['template' ] = config ['template' ].read ()
166195
167- # Initialize LtSender with the config credentials but only
196+ # Initialize devo.sender with the config credentials but only
168197 # if we aren't in batch mode or simulation mode
169198 engine = None
170199 if not (config ['batch_mode' ] or config ['simulation' ]
0 commit comments