libPyshell 0.4.0__tar.gz → 0.4.1__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libPyshell
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Support for writing shell scripts in Python
5
5
  Home-page: https://github.com/skogsbaer/libPyshell
6
6
  Author: Stefan Wehr
@@ -37,6 +37,10 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
37
37
 
38
38
  ## Changelog
39
39
 
40
+ * 0.4.1 (2024-09-12)
41
+ * fix capture handling
42
+ * add failOnError option to rm commands
43
+
40
44
  * 0.4.0 (2024-03-20)
41
45
  * re-implement run in terms of subprocess.run. This fixes a bug that caused stdout to
42
46
  disappear.
@@ -26,6 +26,10 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
26
26
 
27
27
  ## Changelog
28
28
 
29
+ * 0.4.1 (2024-09-12)
30
+ * fix capture handling
31
+ * add failOnError option to rm commands
32
+
29
33
  * 0.4.0 (2024-03-20)
30
34
  * re-implement run in terms of subprocess.run. This fixes a bug that caused stdout to
31
35
  disappear.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libPyshell
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Support for writing shell scripts in Python
5
5
  Home-page: https://github.com/skogsbaer/libPyshell
6
6
  Author: Stefan Wehr
@@ -37,6 +37,10 @@ magicFiles = run(['grep', 'magic'] + files, captureStdout=splitLines, onError='i
37
37
 
38
38
  ## Changelog
39
39
 
40
+ * 0.4.1 (2024-09-12)
41
+ * fix capture handling
42
+ * add failOnError option to rm commands
43
+
40
44
  * 0.4.0 (2024-03-20)
41
45
  * re-implement run in terms of subprocess.run. This fixes a bug that caused stdout to
42
46
  disappear.
@@ -2,7 +2,7 @@
2
2
 
3
3
  from distutils.core import setup
4
4
 
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
 
7
7
  with open("README.md", "r", encoding="utf-8") as fh:
8
8
  long_description = fh.read()
@@ -197,7 +197,7 @@ def _handleCapture(capture: CaptureType) -> Optional[_FILE]:
197
197
  return subprocess.PIPE
198
198
  elif callable(capture):
199
199
  return subprocess.PIPE
200
- elif capture is None:
200
+ elif capture == False:
201
201
  return None
202
202
  else:
203
203
  return capture
@@ -430,13 +430,15 @@ def removeFile(path: str):
430
430
 
431
431
  def cp(src: str, target: str):
432
432
  """
433
- Copy `src` to `target`.
433
+ Copy `src` to `target`. Behaves like the cp shell command.
434
434
 
435
435
  * If `src` is a file and `target` is a file: overwrites `target`.
436
436
  * If `src` is a file and `target` is a dirname: places the copy in directory `target`,
437
437
  with the basename of `src.
438
- * If `src` is a directory then `target` must also be a directory: copies
439
- the `src` directory (*not* its content) to `target`.
438
+ * If `src` is a directory and `target` exists, then `target` must also be a directory:
439
+ copies the `src` directory (*not* its content) to `target`.
440
+ * If `src` is a directory and `target` does not exist: copies the `src` directory
441
+ and names the copy `target`.
440
442
  """
441
443
  if isFile(src):
442
444
  if isDir(target):
@@ -511,22 +513,34 @@ class workingDir:
511
513
  cd(self.old_dir)
512
514
  return False # reraise expection
513
515
 
514
- def rm(path: str, force: bool=False):
516
+ def rm(path: str, force: bool=False, failOnError: bool=True):
515
517
  """
516
518
  Remove the file at `path`.
517
519
  """
518
520
  if force and not exists(path):
519
521
  return
520
- os.remove(path)
522
+ try:
523
+ os.remove(path)
524
+ except Exception as e:
525
+ if failOnError:
526
+ raise
527
+ else:
528
+ sys.stderr.write(str(e) + '\n')
521
529
 
522
- def rmdir(d: str, recursive: bool=False):
530
+ def rmdir(d: str, recursive: bool=False, failOnError: bool=True):
523
531
  """
524
532
  Remove directory `d`. Set `recursive=True` if the directory is not empty.
525
533
  """
526
- if recursive:
527
- shutil.rmtree(d)
528
- else:
529
- os.rmdir(d)
534
+ try:
535
+ if recursive:
536
+ shutil.rmtree(d)
537
+ else:
538
+ os.rmdir(d)
539
+ except Exception as e:
540
+ if failOnError:
541
+ raise
542
+ else:
543
+ sys.stderr.write(str(e) + '\n')
530
544
 
531
545
  # See https://stackoverflow.com/questions/9741351/how-to-find-exit-code-or-reason-when-atexit-callback-is-called-in-python
532
546
  class _ExitHooks(object):
@@ -581,7 +595,7 @@ def _registerAtExit(action: Any, mode: AtExitMode):
581
595
  def mkTempFile(suffix: str='', prefix: str='',
582
596
  dir:Optional[str]=None,
583
597
  deleteAtExit:AtExitMode=True):
584
- """Create a temporary file.
598
+ """Create a temporary file name.
585
599
 
586
600
  `deleteAtExit` controls if and how the file is deleted once the shell sript terminates.
587
601
  It has one of the following values.
@@ -596,7 +610,7 @@ def mkTempFile(suffix: str='', prefix: str='',
596
610
  if deleteAtExit:
597
611
  def action():
598
612
  if isFile(f):
599
- rm(f)
613
+ rm(f, failOnError=False)
600
614
  _registerAtExit(action, deleteAtExit)
601
615
  return f
602
616
 
@@ -610,7 +624,7 @@ def mkTempDir(suffix: str='', prefix: str='tmp',
610
624
  if deleteAtExit:
611
625
  def action():
612
626
  if isDir(d):
613
- rmdir(d, True)
627
+ rmdir(d, recursive=True, failOnError=False)
614
628
  _registerAtExit(action, deleteAtExit)
615
629
  return d
616
630
 
@@ -646,7 +660,7 @@ class tempDir:
646
660
  return False # reraise
647
661
  if self.delete:
648
662
  if isDir(self.dir_to_delete):
649
- rmdir(self.dir_to_delete, recursive=True)
663
+ rmdir(self.dir_to_delete, recursive=True, failOnError=False)
650
664
  return False # reraise expection
651
665
 
652
666
  def ls(d: str, *globs: str) -> list[str]:
File without changes
File without changes
File without changes