multiCMD 1.25__py3-none-any.whl → 1.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
multiCMD.py CHANGED
@@ -18,7 +18,7 @@ import re
18
18
  import itertools
19
19
  import signal
20
20
 
21
- version = '1.25'
21
+ version = '1.27'
22
22
  __version__ = version
23
23
 
24
24
  __running_threads = []
@@ -265,7 +265,7 @@ def __run_command(task,sem, timeout=60, quiet=False,dry_run=False,with_stdErr=Fa
265
265
  return task.stdout
266
266
 
267
267
  def ping(hosts,timeout=1,max_threads=0,quiet=True,dry_run=False,with_stdErr=False,
268
- return_code_only=True,return_object=False,wait_for_return=True):
268
+ return_code_only=False,return_object=False,wait_for_return=True,return_true_false=True):
269
269
  '''
270
270
  Ping multiple hosts
271
271
 
@@ -283,19 +283,31 @@ def ping(hosts,timeout=1,max_threads=0,quiet=True,dry_run=False,with_stdErr=Fals
283
283
  @returns:
284
284
  None | int | list[str] | Task: The output of the command
285
285
  '''
286
+ single_host = False
286
287
  if isinstance(hosts,str):
287
288
  commands = [f'ping -c 1 {hosts}']
288
- return run_commands(commands, timeout=timeout, max_threads=max_threads, quiet=quiet,
289
- dry_run=dry_run, with_stdErr=with_stdErr, return_code_only=return_code_only,
290
- return_object=return_object,wait_for_return=wait_for_return)[0]
291
- commands = [f'ping -c 1 {host}' for host in hosts]
292
- return run_commands(commands, timeout=timeout, max_threads=max_threads, quiet=quiet,
289
+ single_host = True
290
+ else:
291
+ commands = [f'ping -c 1 {host}' for host in hosts]
292
+ if return_true_false:
293
+ return_code_only = True
294
+ results = run_commands(commands, timeout=timeout, max_threads=max_threads, quiet=quiet,
293
295
  dry_run=dry_run, with_stdErr=with_stdErr, return_code_only=return_code_only,
294
296
  return_object=return_object,wait_for_return=wait_for_return)
297
+ if return_true_false:
298
+ if single_host:
299
+ return not results[0]
300
+ else:
301
+ return [not result for result in results]
302
+ else:
303
+ if single_host:
304
+ return results[0]
305
+ else:
306
+ return results
295
307
 
296
308
 
297
309
  def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
298
- return_code_only=False,return_object=False,wait_for_return=True):
310
+ return_code_only=False,return_object=False,wait_for_return=True, sem = None):
299
311
  '''
300
312
  Run a command
301
313
 
@@ -309,13 +321,14 @@ def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_
309
321
  return_code_only: Whether to return only the return code
310
322
  return_object: Whether to return the Task object
311
323
  wait_for_return: Whether to wait for the return of the command
324
+ sem: The semaphore to use for threading
312
325
 
313
326
  @returns:
314
327
  None | int | list[str] | Task: The output of the command
315
328
  '''
316
329
  return run_commands(commands=[command], timeout=timeout, max_threads=max_threads, quiet=quiet,
317
330
  dry_run=dry_run, with_stdErr=with_stdErr, return_code_only=return_code_only,
318
- return_object=return_object,parse=False,wait_for_return=wait_for_return)[0]
331
+ return_object=return_object,parse=False,wait_for_return=wait_for_return,sem=sem)[0]
319
332
 
320
333
  def __format_command(command,expand = False):
321
334
  '''
@@ -354,7 +367,7 @@ def __format_command(command,expand = False):
354
367
  return __format_command(str(command),expand=expand)
355
368
 
356
369
  def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
357
- return_code_only=False,return_object=False, parse = False, wait_for_return = True):
370
+ return_code_only=False,return_object=False, parse = False, wait_for_return = True, sem : threading.Semaphore = None):
358
371
  '''
359
372
  Run multiple commands in parallel
360
373
 
@@ -369,6 +382,7 @@ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,wit
369
382
  return_object: Whether to return the Task object
370
383
  parse: Whether to parse ranged input
371
384
  wait_for_return: Whether to wait for the return of the commands
385
+ sem: The semaphore to use for threading
372
386
 
373
387
  @returns:
374
388
  list: The output of the commands ( list[None] | list[int] | list[list[str]] | list[Task] )
@@ -383,7 +397,8 @@ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,wit
383
397
  if max_threads < 1:
384
398
  max_threads = len(formatedCommands)
385
399
  if max_threads > 1 or not wait_for_return:
386
- sem = threading.Semaphore(max_threads) # Limit concurrent sessions
400
+ if not sem:
401
+ sem = threading.Semaphore(max_threads) # Limit concurrent sessions
387
402
  threads = [threading.Thread(target=__run_command, args=(task,sem,timeout,quiet,dry_run,...),daemon=True) for task in tasks]
388
403
  for thread,task in zip(threads,tasks):
389
404
  task.thread = thread
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: multiCMD
3
- Version: 1.25
3
+ Version: 1.27
4
4
  Summary: Run commands simultaneously
5
5
  Home-page: https://github.com/yufei-pan/multiCMD
6
6
  Author: Yufei Pan
@@ -0,0 +1,6 @@
1
+ multiCMD.py,sha256=YroqJCPegx_Ea-FSNWPzNRdlFWSEmiqt2YN94sqVPw8,18903
2
+ multicmd-1.27.dist-info/METADATA,sha256=TF_qAeuDkNtIgC70KCUZbEwf5PftyStFW_TIyfFU4Go,5640
3
+ multicmd-1.27.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
4
+ multicmd-1.27.dist-info/entry_points.txt,sha256=nSLBkYrcUCQxt1w3LIJkvgOhpRYEC0xAPqNG7u4OYs8,89
5
+ multicmd-1.27.dist-info/top_level.txt,sha256=DSqgftD40G09F3qEjpHRCUNUsGUvGZZG69Sm3YEUiWI,9
6
+ multicmd-1.27.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- multiCMD.py,sha256=jj44YzujdvBUTbBb3S94OP0-TDWA4wXzFd4wEQIqUYQ,18676
2
- multicmd-1.25.dist-info/METADATA,sha256=4NX-fl2sXchCHsTPhvtZkG2ze-gPY7tDB-dAHGXhsH4,5640
3
- multicmd-1.25.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
4
- multicmd-1.25.dist-info/entry_points.txt,sha256=nSLBkYrcUCQxt1w3LIJkvgOhpRYEC0xAPqNG7u4OYs8,89
5
- multicmd-1.25.dist-info/top_level.txt,sha256=DSqgftD40G09F3qEjpHRCUNUsGUvGZZG69Sm3YEUiWI,9
6
- multicmd-1.25.dist-info/RECORD,,