option for workers
This commit is contained in:
parent
0788d18745
commit
457d38b19b
@ -45,18 +45,19 @@ chkbit will
|
|||||||
Run `chkbit PATH` to verify only.
|
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
|
Checks the data integrity of your files. See https://github.com/laktak/chkbit-py
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
PATH
|
PATH directories to check
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-u, --update update indices (without this chkbit will only verify files)
|
-u, --update update indices (without this chkbit will only verify files)
|
||||||
-f, --force force update of damaged items
|
-f, --force force update of damaged items
|
||||||
-i, --verify-index verify files in the index only (will not report new files)
|
-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
|
-q, --quiet quiet, don't show progress/information
|
||||||
-v, --verbose verbose output
|
-v, --verbose verbose output
|
||||||
|
|
||||||
@ -71,6 +72,8 @@ Status codes:
|
|||||||
EXC: internal exception
|
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
|
## Repair
|
||||||
|
|
||||||
chkbit cannot repair damage, its job is simply to detect it.
|
chkbit cannot repair damage, its job is simply to detect it.
|
||||||
|
@ -51,7 +51,10 @@ class Main:
|
|||||||
epilog=STATUS_CODES,
|
epilog=STATUS_CODES,
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
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(
|
parser.add_argument(
|
||||||
"-u",
|
"-u",
|
||||||
@ -71,6 +74,16 @@ class Main:
|
|||||||
help="verify files in the index only (will not report new files)",
|
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(
|
parser.add_argument(
|
||||||
"-q",
|
"-q",
|
||||||
"--quiet",
|
"--quiet",
|
||||||
@ -84,7 +97,7 @@ class Main:
|
|||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
self.verbose = self.args.verbose
|
self.verbose = self.args.verbose
|
||||||
self.quiet = self.args.quiet
|
self.quiet = self.args.quiet
|
||||||
if not self.args.PATH:
|
if not self.args.paths:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
def _res_worker(self):
|
def _res_worker(self):
|
||||||
@ -98,15 +111,22 @@ class Main:
|
|||||||
def process(self):
|
def process(self):
|
||||||
|
|
||||||
self.res_queue = queue.Queue()
|
self.res_queue = queue.Queue()
|
||||||
|
|
||||||
|
# the todo queue is used to distribute the work
|
||||||
|
# to the index threads
|
||||||
todo_queue = queue.Queue()
|
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)
|
todo_queue.put(path)
|
||||||
|
|
||||||
|
# start indexing
|
||||||
workers = [
|
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 = threading.Thread(target=self._res_worker)
|
||||||
res_worker.daemon = True
|
res_worker.daemon = True
|
||||||
res_worker.start()
|
res_worker.start()
|
||||||
@ -142,7 +162,7 @@ class Main:
|
|||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
m = Main()
|
m = Main()
|
||||||
if m.args.PATH:
|
if m.args.paths:
|
||||||
m.process()
|
m.process()
|
||||||
m.print_result()
|
m.print_result()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8"
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="chkbit",
|
name="chkbit",
|
||||||
version="2.1.0",
|
version="2.1.1",
|
||||||
url="https://github.com/laktak/chkbit-py",
|
url="https://github.com/laktak/chkbit-py",
|
||||||
author="Christian Zangl",
|
author="Christian Zangl",
|
||||||
author_email="laktak@cdak.net",
|
author_email="laktak@cdak.net",
|
||||||
|
Reference in New Issue
Block a user