pathlibutil 0.3.2__tar.gz → 0.3.4__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,3 +1,27 @@
1
+ Metadata-Version: 2.1
2
+ Name: pathlibutil
3
+ Version: 0.3.4
4
+ Summary: inherits from pathlib.Path with methods for hashing, copying, deleting and more
5
+ License: MIT
6
+ Keywords: pathlib,hashlib,shutil,urllib.parse,json,urlpath
7
+ Author: Christoph Dörrer
8
+ Author-email: d-chris@web.de
9
+ Requires-Python: >=3.8.1,<4.0.0
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Provides-Extra: 7z
20
+ Requires-Dist: py7zr (>=0.20.2) ; extra == "7z"
21
+ Project-URL: documentation, https://d-chris.github.io/pathlibutil
22
+ Project-URL: repository, https://github.com/d-chris/pathlibutil
23
+ Description-Content-Type: text/markdown
24
+
1
25
  <!--
2
26
  filename: ./README.md
3
27
  -->
@@ -49,7 +73,8 @@ Parse and modify URLs with `pathlibutil.urlpath`.
49
73
 
50
74
  - `pathlibutil.urlpath.UrlPath()` modify URL and easy access the `path` of the url like a `pathlib.PurePosixPath` object.
51
75
  - `pathlibutil.urlpath.UrlNetloc()` to parse and modify the `netloc` part of a URL.
52
- - `pathlibutil.urlpath.normalize_url()` to normalize a URL string.
76
+ - `pathlibutil.urlpath.normalize()` to normalize a URL string.
77
+ - `pathlibutil.urlpath.url_from()` to create a URL from an UNC path object.
53
78
 
54
79
 
55
80
  ## Installation
@@ -296,4 +321,93 @@ os.getcwd is K:/pathlibutil
296
321
  Path.cwd(frozen=True) is K:/pathlibutil/examples
297
322
  Path.cwd(frozen=False) is K:/pathlibutil
298
323
  Path.cwd(frozen=_MEIPASS) is C:/Users/CHRIST~1.DOE/AppData/Local/Temp/_MEI106042
299
- ```
324
+ ```
325
+
326
+ ## Example 7
327
+
328
+ Console application to convert UNC paths to intranet URLs.
329
+
330
+ By default, it checks if the filename and URL are available and copies the
331
+ normalized URL to the clipboard.
332
+
333
+ > `pathlibutil.urlpath.url_from()`
334
+
335
+ ```python
336
+ import argparse
337
+ import sys
338
+
339
+ try:
340
+ import pyperclip
341
+
342
+ import pathlibutil.urlpath as up
343
+ except ModuleNotFoundError as e:
344
+ raise ModuleNotFoundError(f"pip install {e.name.split('.')[0]}") from e
345
+
346
+
347
+ def intranet_from(uncpath: str, check: bool = True) -> str:
348
+ """
349
+ Return the intranet URL for the given UNC path.
350
+ """
351
+
352
+ url = up.url_from(
353
+ uncpath,
354
+ hostname="http://intranet.example.de",
355
+ strict=check,
356
+ )
357
+
358
+ return url.normalize()
359
+
360
+
361
+ def cli():
362
+
363
+ parser = argparse.ArgumentParser(
364
+ description=intranet_from.__doc__,
365
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
366
+ )
367
+
368
+ parser.add_argument(
369
+ "filename",
370
+ nargs="*",
371
+ help="The UNC path to the file.",
372
+ )
373
+ parser.add_argument(
374
+ "-c",
375
+ "--no-check",
376
+ action="store_false",
377
+ dest="check",
378
+ help="Don't check if filename and url is available.",
379
+ )
380
+ parser.add_argument(
381
+ "-s",
382
+ "--silent",
383
+ action="store_true",
384
+ help="Do not print the url to stdout.",
385
+ )
386
+ parser.add_argument(
387
+ "-n",
388
+ "--no-clip",
389
+ action="store_false",
390
+ dest="clip",
391
+ help="Don't copy the url to the clipboard.",
392
+ )
393
+
394
+ args = parser.parse_args()
395
+ filename = " ".join(args.filename)
396
+
397
+ url = intranet_from(filename, check=args.check)
398
+
399
+ if not args.silent:
400
+ print(url)
401
+
402
+ if args.clip:
403
+ pyperclip.copy(url)
404
+
405
+
406
+ if __name__ == "__main__":
407
+ try:
408
+ cli()
409
+ except Exception as e:
410
+ print(e, file=sys.stderr)
411
+ sys.exit(1)
412
+ ```
413
+
@@ -1,28 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: pathlibutil
3
- Version: 0.3.2
4
- Summary: inherits from pathlib.Path with methods for hashing, copying, deleting and more
5
- Home-page: https://d-chris.github.io
6
- License: MIT
7
- Keywords: pathlib,hashlib,shutil,urllib.parse
8
- Author: Christoph Dörrer
9
- Author-email: d-chris@web.de
10
- Requires-Python: >=3.8.1,<4.0.0
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Operating System :: OS Independent
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Programming Language :: Python :: 3.8
20
- Provides-Extra: 7z
21
- Requires-Dist: py7zr (>=0.20.2,<0.21.0) ; extra == "7z"
22
- Project-URL: Documentation, https://d-chris.github.io/pathlibutil
23
- Project-URL: Repository, https://github.com/d-chris/pathlibutil
24
- Description-Content-Type: text/markdown
25
-
26
1
  <!--
27
2
  filename: ./README.md
28
3
  -->
@@ -74,7 +49,8 @@ Parse and modify URLs with `pathlibutil.urlpath`.
74
49
 
75
50
  - `pathlibutil.urlpath.UrlPath()` modify URL and easy access the `path` of the url like a `pathlib.PurePosixPath` object.
76
51
  - `pathlibutil.urlpath.UrlNetloc()` to parse and modify the `netloc` part of a URL.
77
- - `pathlibutil.urlpath.normalize_url()` to normalize a URL string.
52
+ - `pathlibutil.urlpath.normalize()` to normalize a URL string.
53
+ - `pathlibutil.urlpath.url_from()` to create a URL from an UNC path object.
78
54
 
79
55
 
80
56
  ## Installation
@@ -322,3 +298,91 @@ Path.cwd(frozen=True) is K:/pathlibutil/examples
322
298
  Path.cwd(frozen=False) is K:/pathlibutil
323
299
  Path.cwd(frozen=_MEIPASS) is C:/Users/CHRIST~1.DOE/AppData/Local/Temp/_MEI106042
324
300
  ```
301
+
302
+ ## Example 7
303
+
304
+ Console application to convert UNC paths to intranet URLs.
305
+
306
+ By default, it checks if the filename and URL are available and copies the
307
+ normalized URL to the clipboard.
308
+
309
+ > `pathlibutil.urlpath.url_from()`
310
+
311
+ ```python
312
+ import argparse
313
+ import sys
314
+
315
+ try:
316
+ import pyperclip
317
+
318
+ import pathlibutil.urlpath as up
319
+ except ModuleNotFoundError as e:
320
+ raise ModuleNotFoundError(f"pip install {e.name.split('.')[0]}") from e
321
+
322
+
323
+ def intranet_from(uncpath: str, check: bool = True) -> str:
324
+ """
325
+ Return the intranet URL for the given UNC path.
326
+ """
327
+
328
+ url = up.url_from(
329
+ uncpath,
330
+ hostname="http://intranet.example.de",
331
+ strict=check,
332
+ )
333
+
334
+ return url.normalize()
335
+
336
+
337
+ def cli():
338
+
339
+ parser = argparse.ArgumentParser(
340
+ description=intranet_from.__doc__,
341
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
342
+ )
343
+
344
+ parser.add_argument(
345
+ "filename",
346
+ nargs="*",
347
+ help="The UNC path to the file.",
348
+ )
349
+ parser.add_argument(
350
+ "-c",
351
+ "--no-check",
352
+ action="store_false",
353
+ dest="check",
354
+ help="Don't check if filename and url is available.",
355
+ )
356
+ parser.add_argument(
357
+ "-s",
358
+ "--silent",
359
+ action="store_true",
360
+ help="Do not print the url to stdout.",
361
+ )
362
+ parser.add_argument(
363
+ "-n",
364
+ "--no-clip",
365
+ action="store_false",
366
+ dest="clip",
367
+ help="Don't copy the url to the clipboard.",
368
+ )
369
+
370
+ args = parser.parse_args()
371
+ filename = " ".join(args.filename)
372
+
373
+ url = intranet_from(filename, check=args.check)
374
+
375
+ if not args.silent:
376
+ print(url)
377
+
378
+ if args.clip:
379
+ pyperclip.copy(url)
380
+
381
+
382
+ if __name__ == "__main__":
383
+ try:
384
+ cli()
385
+ except Exception as e:
386
+ print(e, file=sys.stderr)
387
+ sys.exit(1)
388
+ ```
@@ -5,4 +5,11 @@
5
5
  from pathlibutil.path import Path, Register7zFormat
6
6
  from pathlibutil.types import ByteInt, StatResult, TimeInt, byteint
7
7
 
8
- __all__ = ["Path", "Register7zFormat", "ByteInt", "byteint", "TimeInt", "StatResult"]
8
+ __all__ = [
9
+ "Path",
10
+ "Register7zFormat",
11
+ "ByteInt",
12
+ "byteint",
13
+ "TimeInt",
14
+ "StatResult",
15
+ ]