option for workers
This commit is contained in:
parent
0788d18745
commit
457d38b19b
@ -45,18 +45,19 @@ chkbit will
|
||||
Run `chkbit PATH` to verify only.
|
||||
|
||||
```
|
||||
usage: chkbit.py [-h] [-u] [-f] [-i] [-q] [-v] [PATH [PATH ...]]
|
||||
usage: chkbit.py [-h] [-u] [-f] [-i] [-w N] [-q] [-v] [PATH [PATH ...]]
|
||||
|
||||
Checks the data integrity of your files. See https://github.com/laktak/chkbit-py
|
||||
|
||||
positional arguments:
|
||||
PATH
|
||||
PATH directories to check
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-u, --update update indices (without this chkbit will only verify files)
|
||||
-f, --force force update of damaged items
|
||||
-i, --verify-index verify files in the index only (will not report new files)
|
||||
-w N, --workers N number of workers to use, default=5
|
||||
-q, --quiet quiet, don't show progress/information
|
||||
-v, --verbose verbose output
|
||||
|
||||
@ -71,6 +72,8 @@ Status codes:
|
||||
EXC: internal exception
|
||||
```
|
||||
|
||||
chkbit is set to use only 5 workers by default so it will not slow your system to a crawl. You can specify a higher number to make it a lot faster (requires about 128kB of memory per worker).
|
||||
|
||||
## Repair
|
||||
|
||||
chkbit cannot repair damage, its job is simply to detect it.
|
||||
|
@ -51,7 +51,10 @@ class Main:
|
||||
epilog=STATUS_CODES,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
parser.add_argument("PATH", nargs="*")
|
||||
|
||||
parser.add_argument(
|
||||
"paths", metavar="PATH", type=str, nargs="*", help="directories to check"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-u",
|
||||
@ -71,6 +74,16 @@ class Main:
|
||||
help="verify files in the index only (will not report new files)",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-w",
|
||||
"--workers",
|
||||
metavar="N",
|
||||
action="store",
|
||||
type=int,
|
||||
default=5,
|
||||
help="number of workers to use, default=5",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
@ -84,7 +97,7 @@ class Main:
|
||||
self.args = parser.parse_args()
|
||||
self.verbose = self.args.verbose
|
||||
self.quiet = self.args.quiet
|
||||
if not self.args.PATH:
|
||||
if not self.args.paths:
|
||||
parser.print_help()
|
||||
|
||||
def _res_worker(self):
|
||||
@ -98,15 +111,22 @@ class Main:
|
||||
def process(self):
|
||||
|
||||
self.res_queue = queue.Queue()
|
||||
|
||||
# the todo queue is used to distribute the work
|
||||
# to the index threads
|
||||
todo_queue = queue.Queue()
|
||||
|
||||
for path in self.args.PATH:
|
||||
# put the initial paths into the queue
|
||||
for path in self.args.paths:
|
||||
todo_queue.put(path)
|
||||
|
||||
# start indexing
|
||||
workers = [
|
||||
IndexThread(idx, self.args, self.res_queue, todo_queue) for idx in range(5)
|
||||
IndexThread(idx, self.args, self.res_queue, todo_queue)
|
||||
for idx in range(self.args.workers)
|
||||
]
|
||||
|
||||
# log the results from the workers
|
||||
res_worker = threading.Thread(target=self._res_worker)
|
||||
res_worker.daemon = True
|
||||
res_worker.start()
|
||||
@ -142,7 +162,7 @@ class Main:
|
||||
def main():
|
||||
try:
|
||||
m = Main()
|
||||
if m.args.PATH:
|
||||
if m.args.paths:
|
||||
m.process()
|
||||
m.print_result()
|
||||
except KeyboardInterrupt:
|
||||
|
Loading…
x
Reference in New Issue
Block a user