Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit196a476

Browse files
committed
sync, truncate: Add--progress/--no-progress support
Progress bars for coreutils are an extension specific topython-userland.
1 parentb8cb848 commit196a476

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

‎pyproject.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ build-backend = "setuptools.build_meta"
66
name ="userland"
77
version ="0.0.2"
88
requires-python =">=3.13"
9+
dependencies = [
10+
"tqdm>=4.67.1"
11+
]
912
authors = [
1013
{name="Expertcoderz",email="expertcoderzx@gmail.com"}
1114
]

‎userland/utilities/sync.py‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
importos
22
importsys
33

4+
fromtqdmimporttqdm
5+
46
from ..importcore
57

68

79
parser=core.create_parser(
8-
usage=("%prog [FILE]...",),
10+
usage=("%prog [OPTION] [FILE]...",),
911
description="Sync the filesystem or write each FILE's blocks to disk.",
1012
)
1113

14+
parser.add_option(
15+
"--progress",
16+
dest="progress",
17+
action="store_true",
18+
help="show a progress bar when syncing files",
19+
)
20+
parser.add_option(
21+
"--no-progress",
22+
dest="progress",
23+
action="store_false",
24+
default=False,
25+
help="do not show a progress bar (default)",
26+
)
27+
1228

1329
@core.command(parser)
14-
defpython_userland_sync(_,args):
30+
defpython_userland_sync(opts,args):
1531
ifargs:
1632
failed=False
1733

18-
fornameinargs:
34+
fornamein (
35+
tqdm(args,ascii=True,desc="Syncing files")ifopts.progresselseargs
36+
):
1937
try:
2038
withopen(name,"rb+")asio:
2139
os.fsync(io)

‎userland/utilities/truncate.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
frompathlibimportPath
33
fromtypingimportCallable
44

5+
fromtqdmimporttqdm
6+
57
from ..importcore
68

79

@@ -13,6 +15,20 @@
1315
description="Shrink or extend each FILE to SIZE.",
1416
)
1517

18+
parser.add_option(
19+
"--progress",
20+
dest="progress",
21+
action="store_true",
22+
help="show a progress bar when truncating files",
23+
)
24+
parser.add_option(
25+
"--no-progress",
26+
dest="progress",
27+
action="store_false",
28+
default=False,
29+
help="do not show a progress bar (default)",
30+
)
31+
1632
parser.add_option("-c","--no-create",action="store_true",help="do not create files")
1733
parser.add_option("-s","--size",help="set or adjust file size by SIZE bytes")
1834
parser.add_option(
@@ -79,7 +95,9 @@ def python_userland_truncate(opts, args):
7995
print(e,file=sys.stderr)
8096
return1
8197

82-
forfileinmap(Path,args):
98+
forfileinmap(
99+
Path,tqdm(args,ascii=True,desc="Truncating files")ifopts.progresselseargs
100+
):
83101
ifnotfile.exists()andopts.no_create:
84102
continue
85103

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp