multiCMD 1.15__tar.gz → 1.17__tar.gz

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.
@@ -1,170 +1,190 @@
1
- Metadata-Version: 2.2
2
- Name: multiCMD
3
- Version: 1.15
4
- Summary: Run commands simultaneously
5
- Home-page: https://github.com/yufei-pan/multiCMD
6
- Author: Yufei Pan
7
- Author-email: pan@zopyr.us
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
10
- Classifier: Operating System :: POSIX :: Linux
11
- Classifier: Operating System :: Microsoft :: Windows
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: argparse
16
- Dynamic: author
17
- Dynamic: author-email
18
- Dynamic: classifier
19
- Dynamic: description
20
- Dynamic: description-content-type
21
- Dynamic: home-page
22
- Dynamic: requires-dist
23
- Dynamic: requires-python
24
- Dynamic: summary
25
-
26
- # multiCMD
27
- A simple script that is able to issue multiple commands and execute them at the same time locally.
28
-
29
- multiCMD can display realtime-ish outputs in color if running multiple commands at the same time.
30
-
31
- Can be used in bash scripts for automation actions.
32
-
33
- Also able to be imported and act as a wrapper for subprocess.
34
-
35
- For each process, it will initialize a thread if using -m/--max_threads > 1
36
-
37
- For each thread, it will use subprocess lib to open a process for the command task
38
-
39
- And it will open two sub threads for processing input and output for the task.
40
-
41
- They input / output threads will be non-blocking.
42
-
43
- Thus using -t/--timeout will work more reliably.
44
-
45
- Note: timeout specifies how many seconds multiCMD will kill the command if NO COMMITTED OUTPUT was detected from the program for this long.
46
-
47
- An output line is considered committed if steram hanlder encounters a '\n' or '\r' character.
48
-
49
-
50
- Install via
51
- ```bash
52
- pip install multiCMD
53
- ```
54
-
55
- multiCMD will be available as
56
- ```bash
57
- mcmd
58
- multiCMD
59
- multicmd
60
- ```
61
-
62
-
63
- ```bash
64
- $ mcmd -h
65
- usage: mcmd [-h] [-t timeout] [-m max_threads] [-q] [-V] command [command ...]
66
-
67
- Run multiple commands in parallel
68
-
69
- positional arguments:
70
- command commands to run
71
-
72
- optional arguments:
73
- -h, --help show this help message and exit
74
- -t timeout, --timeout timeout
75
- timeout for each command
76
- -m max_threads, --max_threads max_threads
77
- maximum number of threads to use
78
- -q, --quiet quiet mode
79
- -V, --version show program's version number and exit
80
- ```
81
-
82
- ```python
83
- def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
84
- return_code_only=False,return_object=False):
85
- '''
86
- Run multiple commands in parallel
87
-
88
- @params:
89
- commands: A list of commands to run
90
- timeout: The timeout for each command
91
- max_threads: The maximum number of threads to use
92
- quiet: Whether to suppress output
93
- dry_run: Whether to simulate running the commands
94
- with_stdErr: Whether to append the standard error output to the standard output
95
- return_code_only: Whether to return only the return code
96
- return_object: Whether to return the Task object
97
-
98
- @returns:
99
- list: The output of the commands ( list[None] | list[int] | list[list[str]] | list[Task] )
100
- '''
101
- def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
102
- return_code_only=False,return_object=False):
103
- '''
104
- Run a command
105
-
106
- @params:
107
- command: The command to run
108
- timeout: The timeout for the command
109
- max_threads: The maximum number of threads to use
110
- quiet: Whether to suppress output
111
- dry_run: Whether to simulate running the command
112
- with_stdErr: Whether to append the standard error output to the standard output
113
- return_code_only: Whether to return only the return code
114
- return_object: Whether to return the Task object
115
-
116
- @returns:
117
- None | int | list[str] | Task: The output of the command
118
- '''
119
- def input_with_timeout_and_countdown(timeout, prompt='Please enter your selection'):
120
- """
121
- Read an input from the user with a timeout and a countdown.
122
-
123
- @params:
124
- timeout: The timeout in seconds
125
- prompt: The prompt to display to the user
126
-
127
- @returns:
128
- str: The input from the user or None if no input was received
129
-
130
- """
131
- def print_progress_bar(iteration, total, prefix='', suffix=''):
132
- '''
133
- Call in a loop to create terminal progress bar
134
- @params:
135
- iteration - Required : current iteration (Int)
136
- total - Required : total iterations (Int)
137
- prefix - Optional : prefix string (Str)
138
- suffix - Optional : suffix string (Str)
139
-
140
- @returns:
141
- None
142
- '''
143
- def get_terminal_size():
144
- '''
145
- Get the terminal size
146
-
147
- @params:
148
- None
149
-
150
- @returns:
151
- (int,int): the number of columns and rows of the terminal
152
- '''
153
- def int_to_color(n, brightness_threshold=500):
154
- '''
155
- Convert an integer to a color
156
-
157
- @params:
158
- n: The integer
159
- brightness_threshold: The brightness threshold
160
-
161
- @returns:
162
- (int,int,int): The RGB color
163
- '''
164
- class Task:
165
- def __init__(self, command):
166
- self.command = command
167
- self.returncode = None
168
- self.stdout = []
169
- self.stderr = []
170
- ```
1
+ Metadata-Version: 2.2
2
+ Name: multiCMD
3
+ Version: 1.17
4
+ Summary: Run commands simultaneously
5
+ Home-page: https://github.com/yufei-pan/multiCMD
6
+ Author: Yufei Pan
7
+ Author-email: pan@zopyr.us
8
+ License: GPLv3+
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: argparse
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: license
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ # multiCMD
28
+ A simple script that is able to issue multiple commands and execute them at the same time locally.
29
+
30
+ multiCMD can display realtime-ish outputs in color if running multiple commands at the same time.
31
+
32
+ Can be used in bash scripts for automation actions.
33
+
34
+ Also able to be imported and act as a wrapper for subprocess.
35
+
36
+ Use return_object=True with run_commands or run_command to get the Task Object (definition below)
37
+
38
+ Use quiet=True and wait_for_return=False to create a daemon thread that async updates the return list / objects when return comes
39
+
40
+ For each process, it will initialize a thread if using -m/--max_threads > 1
41
+
42
+ For each thread, it will use subprocess lib to open a process for the command task
43
+
44
+ And it will open two sub threads for processing input and output for the task.
45
+
46
+ They input / output threads will be non-blocking.
47
+
48
+ Thus using -t/--timeout will work more reliably.
49
+
50
+ Note: timeout specifies how many seconds multiCMD will kill the command if NO COMMITTED OUTPUT was detected from the program for this long.
51
+
52
+ An output line is considered committed if steram hanlder encounters a '\n' or '\r' character.
53
+
54
+
55
+ Install via
56
+ ```bash
57
+ pip install multiCMD
58
+ ```
59
+
60
+ multiCMD will be available as
61
+ ```bash
62
+ mcmd
63
+ multiCMD
64
+ multicmd
65
+ ```
66
+
67
+
68
+ ```bash
69
+ $ mcmd -h
70
+ usage: mcmd [-h] [-t timeout] [-m max_threads] [-q] [-V] command [command ...]
71
+
72
+ Run multiple commands in parallel
73
+
74
+ positional arguments:
75
+ command commands to run
76
+
77
+ options:
78
+ -h, --help show this help message and exit
79
+ -p, --parse Parse ranged input and expand them into multiple commands
80
+ -t timeout, --timeout timeout
81
+ timeout for each command
82
+ -m max_threads, --max_threads max_threads
83
+ maximum number of threads to use
84
+ -q, --quiet quiet mode
85
+ -V, --version show program's version number and exit
86
+ ```
87
+
88
+ ```python
89
+ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
90
+ return_code_only=False,return_object=False, parse = False, wait_for_return = True):
91
+ '''
92
+ Run multiple commands in parallel
93
+
94
+ @params:
95
+ commands: A list of commands to run ( list[str] | list[list[str]] )
96
+ timeout: The timeout for each command
97
+ max_threads: The maximum number of threads to use
98
+ quiet: Whether to suppress output
99
+ dry_run: Whether to simulate running the commands
100
+ with_stdErr: Whether to append the standard error output to the standard output
101
+ return_code_only: Whether to return only the return code
102
+ return_object: Whether to return the Task object
103
+ parse: Whether to parse ranged input
104
+ wait_for_return: Whether to wait for the return of the commands
105
+
106
+ @returns:
107
+ list: The output of the commands ( list[None] | list[int] | list[list[str]] | list[Task] )
108
+ '''
109
+ def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
110
+ return_code_only=False,return_object=False,wait_for_return=True):
111
+ '''
112
+ Run a command
113
+
114
+ @params:
115
+ command: The command to run
116
+ timeout: The timeout for the command
117
+ max_threads: The maximum number of threads to use
118
+ quiet: Whether to suppress output
119
+ dry_run: Whether to simulate running the command
120
+ with_stdErr: Whether to append the standard error output to the standard output
121
+ return_code_only: Whether to return only the return code
122
+ return_object: Whether to return the Task object
123
+ wait_for_return: Whether to wait for the return of the command
124
+
125
+ @returns:
126
+ None | int | list[str] | Task: The output of the command
127
+ '''
128
+ def join_threads(threads=__running_threads,timeout=None):
129
+ '''
130
+ Join threads
131
+
132
+ @params:
133
+ threads: The threads to join
134
+ timeout: The timeout
135
+
136
+ @returns:
137
+ None
138
+ '''
139
+ def input_with_timeout_and_countdown(timeout, prompt='Please enter your selection'):
140
+ """
141
+ Read an input from the user with a timeout and a countdown.
142
+
143
+ @params:
144
+ timeout: The timeout in seconds
145
+ prompt: The prompt to display to the user
146
+
147
+ @returns:
148
+ str: The input from the user or None if no input was received
149
+
150
+ """
151
+ def print_progress_bar(iteration, total, prefix='', suffix=''):
152
+ '''
153
+ Call in a loop to create terminal progress bar
154
+ @params:
155
+ iteration - Required : current iteration (Int)
156
+ total - Required : total iterations (Int)
157
+ prefix - Optional : prefix string (Str)
158
+ suffix - Optional : suffix string (Str)
159
+
160
+ @returns:
161
+ None
162
+ '''
163
+ def get_terminal_size():
164
+ '''
165
+ Get the terminal size
166
+
167
+ @params:
168
+ None
169
+
170
+ @returns:
171
+ (int,int): the number of columns and rows of the terminal
172
+ '''
173
+ def int_to_color(n, brightness_threshold=500):
174
+ '''
175
+ Convert an integer to a color
176
+
177
+ @params:
178
+ n: The integer
179
+ brightness_threshold: The brightness threshold
180
+
181
+ @returns:
182
+ (int,int,int): The RGB color
183
+ '''
184
+ class Task:
185
+ def __init__(self, command):
186
+ self.command = command
187
+ self.returncode = None
188
+ self.stdout = []
189
+ self.stderr = []
190
+ ```
@@ -7,6 +7,10 @@ Can be used in bash scripts for automation actions.
7
7
 
8
8
  Also able to be imported and act as a wrapper for subprocess.
9
9
 
10
+ Use return_object=True with run_commands or run_command to get the Task Object (definition below)
11
+
12
+ Use quiet=True and wait_for_return=False to create a daemon thread that async updates the return list / objects when return comes
13
+
10
14
  For each process, it will initialize a thread if using -m/--max_threads > 1
11
15
 
12
16
  For each thread, it will use subprocess lib to open a process for the command task
@@ -44,8 +48,9 @@ Run multiple commands in parallel
44
48
  positional arguments:
45
49
  command commands to run
46
50
 
47
- optional arguments:
51
+ options:
48
52
  -h, --help show this help message and exit
53
+ -p, --parse Parse ranged input and expand them into multiple commands
49
54
  -t timeout, --timeout timeout
50
55
  timeout for each command
51
56
  -m max_threads, --max_threads max_threads
@@ -56,12 +61,12 @@ optional arguments:
56
61
 
57
62
  ```python
58
63
  def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
59
- return_code_only=False,return_object=False):
64
+ return_code_only=False,return_object=False, parse = False, wait_for_return = True):
60
65
  '''
61
66
  Run multiple commands in parallel
62
67
 
63
68
  @params:
64
- commands: A list of commands to run
69
+ commands: A list of commands to run ( list[str] | list[list[str]] )
65
70
  timeout: The timeout for each command
66
71
  max_threads: The maximum number of threads to use
67
72
  quiet: Whether to suppress output
@@ -69,12 +74,14 @@ def run_commands(commands, timeout=0,max_threads=1,quiet=False,dry_run=False,wit
69
74
  with_stdErr: Whether to append the standard error output to the standard output
70
75
  return_code_only: Whether to return only the return code
71
76
  return_object: Whether to return the Task object
77
+ parse: Whether to parse ranged input
78
+ wait_for_return: Whether to wait for the return of the commands
72
79
 
73
80
  @returns:
74
81
  list: The output of the commands ( list[None] | list[int] | list[list[str]] | list[Task] )
75
- '''
82
+ '''
76
83
  def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_stdErr=False,
77
- return_code_only=False,return_object=False):
84
+ return_code_only=False,return_object=False,wait_for_return=True):
78
85
  '''
79
86
  Run a command
80
87
 
@@ -87,10 +94,22 @@ def run_command(command, timeout=0,max_threads=1,quiet=False,dry_run=False,with_
87
94
  with_stdErr: Whether to append the standard error output to the standard output
88
95
  return_code_only: Whether to return only the return code
89
96
  return_object: Whether to return the Task object
97
+ wait_for_return: Whether to wait for the return of the command
90
98
 
91
99
  @returns:
92
100
  None | int | list[str] | Task: The output of the command
93
101
  '''
102
+ def join_threads(threads=__running_threads,timeout=None):
103
+ '''
104
+ Join threads
105
+
106
+ @params:
107
+ threads: The threads to join
108
+ timeout: The timeout
109
+
110
+ @returns:
111
+ None
112
+ '''
94
113
  def input_with_timeout_and_countdown(timeout, prompt='Please enter your selection'):
95
114
  """
96
115
  Read an input from the user with a timeout and a countdown.