bluer-objects 6.309.1__py3-none-any.whl → 6.322.1__py3-none-any.whl

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.

Potentially problematic release.


This version of bluer-objects might be problematic. Click here for more details.

@@ -1,8 +1,19 @@
1
1
  #! /usr/bin/env bash
2
2
 
3
3
  function bluer_objects_file() {
4
- python3 -m bluer_objects.file \
5
- "$1" \
6
- --filename "$2" \
7
- "${@:3}"
4
+ local options=$1
5
+ local do_sudo=$(bluer_ai_option_int "$options" sudo 0)
6
+
7
+ local task=$2
8
+
9
+ local prefix=""
10
+ [[ "$do_sudo" == 1 ]] &&
11
+ prefix="sudo -E"
12
+
13
+ local filename=$3
14
+
15
+ $prefix $(which python) -m bluer_objects.file \
16
+ "$task" \
17
+ --filename "$filename" \
18
+ "${@:4}"
8
19
  }
@@ -0,0 +1,64 @@
1
+ #! /usr/bin/env bash
2
+
3
+ function test_file_asset() {
4
+ echo $abcli_path_git/bluer-objects/bluer_objects/.abcli/tests/file.sh
5
+ }
6
+
7
+ function test_file_replace() {
8
+ local options=$1
9
+
10
+ local filename=$abcli_path_git/file.sh
11
+
12
+ cp -v \
13
+ $(test_file_asset) \
14
+ $filename
15
+ [[ $? -ne 0 ]] && return 1
16
+
17
+ bluer_objects_file - \
18
+ replace \
19
+ $filename \
20
+ --this function+local \
21
+ --that FUNCTION+LOCAL \
22
+ --cat 1 \
23
+ "${@:2}"
24
+ [[ $? -ne 0 ]] && return 1
25
+ bluer_ai_hr
26
+
27
+ # ---
28
+
29
+ bluer_objects_file - \
30
+ replace \
31
+ $filename \
32
+ --this "FUNCTION test_file_asset() {+echo" \
33
+ --that ":)+:(" \
34
+ --cat 1 \
35
+ --whole_line 1 \
36
+ "${@:2}"
37
+ [[ $? -ne 0 ]] && return 1
38
+ rm -v $filename
39
+ }
40
+
41
+ function test_file_size() {
42
+ local options=$1
43
+
44
+ local size=$(bluer_objects_file - \
45
+ size \
46
+ $(test_file_asset))
47
+
48
+ bluer_ai_assert \
49
+ "$size" \
50
+ "1.18 kB"
51
+ [[ $? -ne 0 ]] && return 1
52
+ bluer_ai_hr
53
+
54
+ # ---
55
+
56
+ local size=$(bluer_objects_file - \
57
+ size \
58
+ $(test_file_asset) \
59
+ --pretty 0)
60
+
61
+ bluer_ai_assert \
62
+ "$size" \
63
+ "1209"
64
+ }
@@ -38,6 +38,10 @@ function test_bluer_objects_help() {
38
38
  \
39
39
  "@ls" \
40
40
  \
41
+ "@file" \
42
+ "@file replace" \
43
+ "@file size" \
44
+ \
41
45
  "@host" \
42
46
  "@host get" \
43
47
  "@host reboot" \
@@ -41,6 +41,7 @@ def build_me() -> bool:
41
41
  "assets",
42
42
  "clone",
43
43
  "download",
44
+ "file",
44
45
  "gif",
45
46
  "host",
46
47
  "ls",
bluer_objects/__init__.py CHANGED
@@ -4,7 +4,7 @@ ICON = "🌀"
4
4
 
5
5
  DESCRIPTION = f"{ICON} Object management in Bash."
6
6
 
7
- VERSION = "6.309.1"
7
+ VERSION = "6.322.1"
8
8
 
9
9
  REPO_NAME = "bluer-objects"
10
10
 
@@ -31,24 +31,69 @@ parser.add_argument(
31
31
  help="<that-1+that-2+that-3>",
32
32
  )
33
33
  parser.add_argument(
34
- "--size",
34
+ "--pretty",
35
35
  type=int,
36
- default=16,
36
+ default=1,
37
+ help="0 | 1",
38
+ )
39
+ parser.add_argument(
40
+ "--save",
41
+ type=int,
42
+ default=1,
43
+ help="0 | 1",
44
+ )
45
+ parser.add_argument(
46
+ "--whole_line",
47
+ type=int,
48
+ default=0,
49
+ help="0 | 1",
50
+ )
51
+ parser.add_argument(
52
+ "--log",
53
+ type=int,
54
+ default=0,
55
+ help="0 | 1",
56
+ )
57
+ parser.add_argument(
58
+ "--cat",
59
+ type=int,
60
+ default=0,
61
+ help="0 | 1",
37
62
  )
38
63
  args = parser.parse_args()
39
64
 
40
65
  success = False
41
66
  if args.task == "replace":
42
- logger.info(f"{NAME}.{args.task}: {args.this} -> {args.that} in {args.filename}")
67
+ logger.info(
68
+ f'{NAME}.{args.task}: "{args.this}" -> "{args.that}" in {args.filename}'
69
+ )
43
70
 
44
- success, content = file.load_text(args.filename)
71
+ success, content = file.load_text(
72
+ args.filename,
73
+ log=args.log == 1,
74
+ )
45
75
  if success:
46
76
  for this, that in tqdm(zip(args.this.split("+"), args.that.split("+"))):
47
- content = [line.replace(this, that) for line in content]
77
+ if args.whole_line:
78
+ content = [that if line == this else line for line in content]
79
+ else:
80
+ content = [line.replace(this, that) for line in content]
81
+
82
+ if args.save == 1:
83
+ success = file.save_text(
84
+ args.filename,
85
+ content,
86
+ log=args.log == 1,
87
+ )
88
+
89
+ if success and args.cat:
90
+ for line in content:
91
+ if any(this in line for this in args.this.split("+")):
92
+ logger.info(line)
48
93
 
49
- success = file.save_text(args.filename, content)
50
94
  elif args.task == "size":
51
- print(string.pretty_bytes(file.size(args.filename)))
95
+ size = file.size(args.filename)
96
+ print(string.pretty_bytes(size) if args.pretty == 1 else size)
52
97
  success = True
53
98
  else:
54
99
  success = None
@@ -1,4 +1,4 @@
1
- from typing import Any, Dict, List
1
+ from typing import Any, Dict, List, Union
2
2
  import yaml
3
3
  import numpy as np
4
4
  import json
@@ -30,9 +30,15 @@ def finish_saving(
30
30
  success: bool,
31
31
  message: str,
32
32
  log: bool = True,
33
+ exception: Union[Exception, None] = None,
33
34
  ) -> bool:
34
35
  if not success:
35
- crash_report(f"{message}: failed.")
36
+ crash_report(
37
+ "{}: failed: {}".format(
38
+ message,
39
+ exception,
40
+ )
41
+ )
36
42
  elif log:
37
43
  logger.info(message)
38
44
 
@@ -246,12 +252,14 @@ def save_yaml(
246
252
  if not prepare_for_saving(filename):
247
253
  return False
248
254
 
255
+ exception = None
249
256
  success = True
250
257
  try:
251
258
  with open(filename, "w") as f:
252
259
  yaml.dump(data, f)
253
- except:
260
+ except Exception as e:
254
261
  success = False
262
+ exception = e
255
263
 
256
264
  return finish_saving(
257
265
  success,
@@ -261,4 +269,5 @@ def save_yaml(
261
269
  filename,
262
270
  ),
263
271
  log,
272
+ exception,
264
273
  )
@@ -0,0 +1,59 @@
1
+ from typing import List
2
+
3
+ from bluer_options.terminal import show_usage, xtra
4
+
5
+
6
+ def help_replace(
7
+ tokens: List[str],
8
+ mono: bool,
9
+ ) -> str:
10
+ options = xtra("sudo", mono=mono)
11
+
12
+ args = [
13
+ "--cat 1",
14
+ "--save 0",
15
+ "--this this-1+this-2",
16
+ "--that that-1+that-2",
17
+ "--whole_line 1",
18
+ ]
19
+
20
+ return show_usage(
21
+ [
22
+ "@file",
23
+ f"[{options}]",
24
+ "replace",
25
+ "<filename>",
26
+ ]
27
+ + args,
28
+ "<this> -> <that> in <filename>.",
29
+ mono=mono,
30
+ )
31
+
32
+
33
+ def help_size(
34
+ tokens: List[str],
35
+ mono: bool,
36
+ ) -> str:
37
+ options = "-"
38
+
39
+ args = [
40
+ "--pretty 0",
41
+ ]
42
+
43
+ return show_usage(
44
+ [
45
+ "@file",
46
+ f"[{options}]",
47
+ "size",
48
+ "<filename>",
49
+ ]
50
+ + args,
51
+ "size of <filename>",
52
+ mono=mono,
53
+ )
54
+
55
+
56
+ help_functions = {
57
+ "replace": help_replace,
58
+ "size": help_size,
59
+ }
@@ -6,6 +6,7 @@ from bluer_objects.help.clone import help_clone
6
6
  from bluer_objects.help.create_test_asset import help_create_test_asset
7
7
  from bluer_objects.help.download import help_download
8
8
  from bluer_objects.help.gif import help_functions as help_gif
9
+ from bluer_objects.help.file import help_functions as help_file
9
10
  from bluer_objects.help.host import help_functions as help_host
10
11
  from bluer_objects.help.ls import help_ls
11
12
  from bluer_objects.help.metadata import help_functions as help_metadata
@@ -21,6 +22,7 @@ help_functions.update(
21
22
  "clone": help_clone,
22
23
  "create_test_asset": help_create_test_asset,
23
24
  "download": help_download,
25
+ "file": help_file,
24
26
  "gif": help_gif,
25
27
  "host": help_host,
26
28
  "ls": help_ls,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_objects
3
- Version: 6.309.1
3
+ Version: 6.322.1
4
4
  Summary: 🌀 Object management in Bash.
5
5
  Home-page: https://github.com/kamangir/bluer-objects
6
6
  Author: Arash Abadpour (Kamangir)
@@ -65,6 +65,6 @@ pip install bluer-objects
65
65
 
66
66
  [![pylint](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/bluer-objects.svg)](https://pypi.org/project/bluer-objects/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/bluer-objects)](https://pypistats.org/packages/bluer-objects)
67
67
 
68
- built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.309.1`](https://github.com/kamangir/bluer-objects).
68
+ built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.322.1`](https://github.com/kamangir/bluer-objects).
69
69
 
70
70
  built by 🌀 [`blueness-3.118.1`](https://github.com/kamangir/blueness).
@@ -1,4 +1,4 @@
1
- bluer_objects/__init__.py,sha256=oIlM2xeIepu5cmzABGmAKpSHdhD0sO8jRADh8g-v9fg,315
1
+ bluer_objects/__init__.py,sha256=8s1PgZJPlJ4pc1gocF3kBql5DyMVUcQ5FaRcCFqdz4M,315
2
2
  bluer_objects/__main__.py,sha256=Yqfov833_hJuRne19WrGhT5DWAPtdffpoMxeSXS7EGw,359
3
3
  bluer_objects/config.env,sha256=ReX0OSH_dK2tdD4-zAlp-427BB57yw8uDTS6tLYN4K0,270
4
4
  bluer_objects/env.py,sha256=ecwldUVsamxAjOI0a6PmbZPcyhdUZgzJ-nhAPh0CJRo,2085
@@ -16,7 +16,7 @@ bluer_objects/.abcli/bluer_objects.sh,sha256=x7qf8hSAp3dAl0Hes4J07vL6qP-mWFUkJhv
16
16
  bluer_objects/.abcli/clone.sh,sha256=KqC5d4MAXwo7UZGhKnfCq9k9CCSl3I1dpU1igYs0Yrs,1975
17
17
  bluer_objects/.abcli/create_test_asset.sh,sha256=ONIdad_WRjZWdW6V2RalRW2qSJwybEwzU-_KsvaJ9og,245
18
18
  bluer_objects/.abcli/download.sh,sha256=SKv4JyjcWjOutK95-gurCqbRjpmcrmzxASEEdT23Ob4,650
19
- bluer_objects/.abcli/file.sh,sha256=djcHSFS8fqlCsoDyZKmimNTzd-jOUnxbOFpL7xq_hGk,150
19
+ bluer_objects/.abcli/file.sh,sha256=5yG-QCqQyudp7ZhJy6PcVcmN40vynUI-URMmO6IO21I,374
20
20
  bluer_objects/.abcli/gif.sh,sha256=cskDoi_BJq5phOAqgJouxH2biC2z3LlDgd9JHAQqvM0,1363
21
21
  bluer_objects/.abcli/host.sh,sha256=rOTrxGEYk4ikJGSvqCzNNfJDVEvAebOqGutVqJpSRxs,1051
22
22
  bluer_objects/.abcli/ls.sh,sha256=9IGfGopZNdpkSwA31hXsRG7Ap0KzY3SGAM9takLQe24,639
@@ -54,8 +54,9 @@ bluer_objects/.abcli/storage/status.sh,sha256=HRbQq9EhoZ1S-GHXOTeclSOTbV-hrEieGA
54
54
  bluer_objects/.abcli/tests/README.sh,sha256=gk2KuNLFTuV3qdVgH8BNfJmur3gZoSV8EwLboVjrCgM,150
55
55
  bluer_objects/.abcli/tests/clone.sh,sha256=Rl9pHvmRJ4H-y-iMA80q11UdSZFrguNaMTez0LTtJjA,473
56
56
  bluer_objects/.abcli/tests/create_test_asset.sh,sha256=onRGc3VjDWA7On3isxKD3J7mxA6n349AVXRj90Z3Jzc,386
57
+ bluer_objects/.abcli/tests/file.sh,sha256=1PSlslmfA41nK0iQHwcelTvXT8LAqswF83vcgK98DYU,1209
57
58
  bluer_objects/.abcli/tests/gif.sh,sha256=qLbVHcvndl8s3YDHd35T06VR5reAdV-TN7eTXHgTn-s,488
58
- bluer_objects/.abcli/tests/help.sh,sha256=J8AnCuPcPyMM_eYN5OjqzU3IaTrZVKDqvh2WSm3GfwM,1989
59
+ bluer_objects/.abcli/tests/help.sh,sha256=5B2xKSjVLV2XYzZ_hNDgIqzxiIKhYra_vMgr4z80vq8,2066
59
60
  bluer_objects/.abcli/tests/host.sh,sha256=GBuTLNw1sU3fAb5jS-ew_qAfovVCQ5CLaz5ad04IkoA,144
60
61
  bluer_objects/.abcli/tests/ls.sh,sha256=l8t2YW5-XbAFC35sAfX0XjAJQjsoz8i-_RnDaLXN-G8,747
61
62
  bluer_objects/.abcli/tests/metadata.sh,sha256=OP1c0h0TSlDycrv0UglKLyBtTQwqh9M0nqVAdQUzkno,1723
@@ -73,7 +74,7 @@ bluer_objects/.abcli/tests/web_is_accessible.sh,sha256=3R33_LQM9PIfl8Bks4HrPHp4u
73
74
  bluer_objects/.abcli/tests/web_where_am_ai.sh,sha256=BJ9G_m4id8cx_UB_l_jV2xY6AfQEpG7O4IBsuVjodxk,104
74
75
  bluer_objects/.abcli/web/is_accessible.sh,sha256=Luv_6IvpscRYx7f39V0RnkkNEWTRfVGyQVUeij3iqa0,262
75
76
  bluer_objects/.abcli/web/where_am_i.sh,sha256=QPBXFo6Ni4pZEoOx0rtuJUxk6tOlp0ESMyAc9YPy9zg,92
76
- bluer_objects/README/__init__.py,sha256=AG9_REFcYVrfMbzK4y02Omie-fCjf6UBP4OnJyNSZ6w,1434
77
+ bluer_objects/README/__init__.py,sha256=YHZCAHdfwLpHXD8mxEZgV7epwHjiUl7kulH2NAWPbrs,1458
77
78
  bluer_objects/README/consts.py,sha256=GYQ8EikslsUfr8JcrXoU0w4eMIGWpIiNmlchTQbSYV0,803
78
79
  bluer_objects/README/functions.py,sha256=PvFawBlJ8IginQn8Kk1QewAyOYRQ4wCuRKpJwr5mUJ8,5844
79
80
  bluer_objects/README/items.py,sha256=CiED7xNwqtCzgzmfhTZvgoqpcmW2ilQYhcV8DVFUVkk,2389
@@ -82,11 +83,11 @@ bluer_objects/assets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
82
83
  bluer_objects/assets/__main__.py,sha256=X1s4ABevs8y5pafPIhZBj5oFX_kMOLWLTMaCFF6_Rio,1064
83
84
  bluer_objects/assets/functions.py,sha256=ZxvjbM_XBRJJewAyE8qdzTZdisQTviFdShYL9cVjM_E,1497
84
85
  bluer_objects/file/__init__.py,sha256=c_79ipBkKl6OFDimOev0vnaVdpUk-Bl3oJUapOreMXc,681
85
- bluer_objects/file/__main__.py,sha256=v2IXWvZeh_B2sGYWzv1CiUY-7HWHXXghZM5M4IPjbu4,1277
86
+ bluer_objects/file/__main__.py,sha256=katbvYg2ykEcs14ZY1kvCKaA6KB_vhlPCLPuJlMX_kY,2165
86
87
  bluer_objects/file/classes.py,sha256=TRgeRP2yxInPkBnywhuB4BsoBcBRA3UmQzX1dI43UxU,872
87
88
  bluer_objects/file/functions.py,sha256=YBJFaI5l-bY1LSz8S_hMhbCmym6cULZTF5fzP2W4Osk,6604
88
89
  bluer_objects/file/load.py,sha256=1zt5xC95HFr89G9lsi3gCJMSvC4Bt0vVeeUEf3NjpOQ,4281
89
- bluer_objects/file/save.py,sha256=eXl5pM8Q29Jq8skVkZkU6THoqyMd2FkfFIPgO0-NarM,5056
90
+ bluer_objects/file/save.py,sha256=IuSbK6GExzOhHqaVfAhoGRqtgCTaon3Fr1T7rSzyV3w,5277
90
91
  bluer_objects/graphics/__init__.py,sha256=Dd0kQqN7Ldvp1N9oyIirPZ6W3IdUtfPj2u21Bf4W_MI,213
91
92
  bluer_objects/graphics/__main__.py,sha256=5_acfal1MnfzhDrp_pfDbC7oy5uzf6vDiiG3lvgx4VU,2041
92
93
  bluer_objects/graphics/frame.py,sha256=WcSn-0oqDw48Akmn_bwcjDC9U_kKqRYRoGWYPoKyFvY,321
@@ -100,7 +101,8 @@ bluer_objects/help/assets.py,sha256=j_Ur84bQFv25wCA6j-ZFcag88LvqyjQyoJfNEd9Bdc8,
100
101
  bluer_objects/help/clone.py,sha256=PDnQs7zc4sqmoBHPjVRfX7jIaePiohPGCNA5bxeerik,553
101
102
  bluer_objects/help/create_test_asset.py,sha256=oxJORm2qk4b_q7EC6-dEuNu1_pK9Ri60PcHhrE8ruxM,375
102
103
  bluer_objects/help/download.py,sha256=9zC_IvH4p2vMXb_qcAS176CBFp5fJe4Z9DFMPdSGBac,751
103
- bluer_objects/help/functions.py,sha256=wgHOtkhEv7oQYcRpiTH6J_70lGKqLbxoBOBV4_O8LIU,1213
104
+ bluer_objects/help/file.py,sha256=WE-BoeWNTJC9-GpmDaFPpwmB1bS7NlWHDbSAwtXvY4g,970
105
+ bluer_objects/help/functions.py,sha256=faOjkzqlA4mHqIUR4v2-nE7uH6L0weqI1F5a66_H1t0,1304
104
106
  bluer_objects/help/gif.py,sha256=0yrTJ0U-vyqc94GH5xstAc_C9Ld0pxptdBusOpnbfzQ,1007
105
107
  bluer_objects/help/host.py,sha256=cq4Y8mo71pqJ0AUjCGkj3smZ-MOTo9aqyxm8q2FWVAs,1050
106
108
  bluer_objects/help/ls.py,sha256=lbYo6tyNdepxr-0R5ICkFMNylCuibYxsgVPlgHRR1cQ,957
@@ -184,8 +186,8 @@ bluer_objects/tests/test_web_is_accessible.py,sha256=2Y20NAEDMblg0MKnhnqcfw3XVKE
184
186
  bluer_objects/web/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
185
187
  bluer_objects/web/__main__.py,sha256=xf2Ob54FI8JEokfGhFmiyOBdD9nBactwqmZvsKsdioU,624
186
188
  bluer_objects/web/functions.py,sha256=KNufAFOc6N3BYf83lN2rUpKUdsnzb2anWyp9koFRVUo,172
187
- bluer_objects-6.309.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
188
- bluer_objects-6.309.1.dist-info/METADATA,sha256=hVrsasnK8GnBDs7cnu-z7FFrbqhezumfoHJUy0F6j7A,3780
189
- bluer_objects-6.309.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
190
- bluer_objects-6.309.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
191
- bluer_objects-6.309.1.dist-info/RECORD,,
189
+ bluer_objects-6.322.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
190
+ bluer_objects-6.322.1.dist-info/METADATA,sha256=YZCM8792s_KHOnuBzk1wcEMeMbybhULXJR156RLFKBk,3780
191
+ bluer_objects-6.322.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
192
+ bluer_objects-6.322.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
193
+ bluer_objects-6.322.1.dist-info/RECORD,,