addftool 0.0.3__py3-none-any.whl → 0.0.5__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.
addftool/blob.py CHANGED
@@ -1,11 +1,13 @@
1
1
  import argparse
2
2
  import requests
3
- import subprocess
4
3
  import os
5
4
  import json
6
5
  import yaml
6
+ import tempfile
7
7
  from cryptography.fernet import Fernet
8
8
 
9
+ from .util import execute_command
10
+
9
11
 
10
12
  def add_api(parser):
11
13
  parser.add_argument("-k", "--key", help="f key", required=True)
@@ -23,17 +25,6 @@ def get_ubuntu_version():
23
25
  return "22.04"
24
26
 
25
27
 
26
- def execute_command(command, to_file=None):
27
- if to_file is not None:
28
- to_file.write(command + "\n")
29
- return None
30
- else:
31
- print("Execute command: ", command)
32
- result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read().decode()
33
- print("Result: ", result)
34
- return result
35
-
36
-
37
28
  def create_dir_for_current_user(dir_path, sudo=False):
38
29
  command = f"mkdir -p {dir_path}"
39
30
  if sudo:
@@ -138,11 +129,16 @@ def mount_main(args):
138
129
  create_dir_for_current_user(args.buffer, sudo=args.sudo)
139
130
  create_dir_for_current_user(args.mount, sudo=args.sudo)
140
131
 
141
- # write config file into /tmp/config.yaml
132
+ # write config file into tempfile
142
133
 
143
- temp_config = "/tmp/config.yaml"
134
+ temp_config_dir = tempfile.mktemp()
135
+ print("Create temp config dir: ", temp_config_dir)
136
+ os.makedirs(temp_config_dir, exist_ok=True)
137
+ temp_config = os.path.join(temp_config_dir, "blobfuse2.yaml")
144
138
  with open(temp_config, 'w') as stream:
145
139
  yaml.dump(template, stream)
140
+
141
+ print("Create config file: ", temp_config)
146
142
 
147
143
  command = f"blobfuse2 mount {args.mount} --config-file={temp_config}"
148
144
  execute_command(command)
addftool/tool.py ADDED
@@ -0,0 +1,79 @@
1
+ import argparse
2
+ import os
3
+
4
+ from .util import execute_command
5
+
6
+
7
+ def init_vscode():
8
+ to_install = [
9
+ "github.copilot",
10
+ "github.copilot-chat",
11
+ "ms-python.debugpy",
12
+ "ms-python.python",
13
+ "ms-python.vscode-pylance",
14
+ "ms-toolsai.jupyter",
15
+ "ms-toolsai.jupyter-keymap",
16
+ "ms-toolsai.jupyter-renderers",
17
+ "ms-toolsai.vscode-jupyter-cell-tags",
18
+ "ms-toolsai.vscode-jupyter-slideshow",
19
+ ]
20
+ for ext in to_install:
21
+ execute_command(f"code --install-extension {ext}")
22
+
23
+
24
+ def add_alias():
25
+ # add to ~/.bashrc
26
+
27
+ home_dir = os.path.expanduser("~")
28
+ bashrc_path = os.path.join(home_dir, ".bashrc")
29
+
30
+ # check if already added
31
+ with open(bashrc_path) as f:
32
+ for line in f:
33
+ if line.startswith("# Addf's alias"):
34
+ print("Already added")
35
+ return
36
+
37
+ to_add = [
38
+ "alias pull='git pull origin'",
39
+ "alias dupwd='du -h --max-depth=1 ./'",
40
+ ]
41
+
42
+ with open(bashrc_path, "a") as f:
43
+ f.write("\n")
44
+ f.write("# Addf's alias\n")
45
+ for line in to_add:
46
+ f.write(line + "\n")
47
+
48
+
49
+ def main():
50
+ parser = argparse.ArgumentParser(description="Addf's tool")
51
+
52
+ parser.add_argument('--init', default="", type=str, help="init")
53
+
54
+ args = parser.parse_args()
55
+
56
+ if args.init:
57
+ to_do = args.init.strip()
58
+ if to_do == 'vscode':
59
+ init_vscode()
60
+ elif to_do == 'git':
61
+ execute_command('git config --global user.name "addf400"')
62
+ execute_command('git config --global user.email "addf400@foxmail.com"')
63
+ elif to_do == 'alias':
64
+ add_alias()
65
+ elif to_do == 'all':
66
+ init_vscode()
67
+ execute_command('git config --global user.name "addf400"')
68
+ execute_command('git config --global user.email "addf400@foxmail.com"')
69
+ add_alias()
70
+ else:
71
+ print("No such init option")
72
+
73
+
74
+ def pull():
75
+ execute_command("git pull origin")
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
addftool/util.py CHANGED
@@ -1,32 +1,12 @@
1
- def rangeexpand(txt):
2
- lst = []
3
- for r in txt.split(','):
4
- if '-' in r[1:]:
5
- r0, r1 = r[1:].split('-', 1)
6
- r1 = r1.strip()
7
- lst += range(int(r[0] + r0), int(r1) + 1)
8
- elif not r.strip():
9
- continue
10
- else:
11
- lst.append(int(r.strip()))
12
- return lst
13
-
14
-
15
- def test_rangeexpand():
16
- import pytest
17
-
18
- assert rangeexpand('1, 3-5, 7') == [1, 3, 4, 5, 7]
19
- assert rangeexpand('1, 3-5, 7, 10-12') == [1, 3, 4, 5, 7, 10, 11, 12]
20
- assert rangeexpand('1-5') == [1, 2, 3, 4, 5]
21
- assert rangeexpand('1-5, 7-10') == [1, 2, 3, 4, 5, 7, 8, 9, 10]
22
- assert rangeexpand('') == []
23
- assert rangeexpand('1') == [1]
24
- assert rangeexpand('1-1') == [1]
25
- assert rangeexpand('1-1, 3-3, 5-5') == [1, 3, 5]
26
- assert rangeexpand('1-1, 3-3, 5-5, 7-7') == [1, 3, 5, 7]
27
-
28
- with pytest.raises(ValueError):
29
- rangeexpand('1-2-3')
30
-
31
- with pytest.raises(ValueError):
32
- rangeexpand('1 7-9')
1
+ import subprocess
2
+
3
+
4
+ def execute_command(command, to_file=None):
5
+ if to_file is not None:
6
+ to_file.write(command + "\n")
7
+ return None
8
+ else:
9
+ print("Execute command: ", command)
10
+ result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read().decode()
11
+ print("Result: ", result)
12
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: addftool
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  License-File: LICENSE
5
5
  Requires-Dist: cryptography
6
6
  Requires-Dist: requests
@@ -0,0 +1,10 @@
1
+ addftool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ addftool/blob.py,sha256=NPhtkcM2XvZrAmCKsx6KSEhpDR0BAPKdjiZHFMkVU2c,6922
3
+ addftool/tool.py,sha256=EuKQ2t2InN7yB-_oYLcdsA7vRqzRGTunwIxplUSqEG0,2054
4
+ addftool/util.py,sha256=Q3A68vJDxgfeNiEFmk54HuMuworVndocXpSbVpvGMfc,362
5
+ addftool-0.0.5.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
6
+ addftool-0.0.5.dist-info/METADATA,sha256=9ObJMQaI4yAiHPkQbd1ItXmlh-2Y8_Iq190qttlKz74,149
7
+ addftool-0.0.5.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
8
+ addftool-0.0.5.dist-info/entry_points.txt,sha256=h5TlQy4AQw-J55HqI7FRkIVRUfw-x3pStFWCoYtoCTM,78
9
+ addftool-0.0.5.dist-info/top_level.txt,sha256=jqj56-plrBbyzY0tIxB6wPzjAA8kte4hUlajyyQygN4,9
10
+ addftool-0.0.5.dist-info/RECORD,,
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
2
  addfblob = addftool.blob:main
3
+ addftool = addftool.tool:main
@@ -1,9 +0,0 @@
1
- addftool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- addftool/blob.py,sha256=iD4CJgMhk4ooFZ1rb7NLHxXT6aG--_QrjqFlecGWSeE,7017
3
- addftool/util.py,sha256=gx-pqNJk31tmWtRJvZrIkI15ER7QZg9FtaM_OyP0JqU,975
4
- addftool-0.0.3.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
5
- addftool-0.0.3.dist-info/METADATA,sha256=ov_H_kPjm_Rw2Ihdb_MNsrtHSxEiXWpu5R29NrIeLWo,149
6
- addftool-0.0.3.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
7
- addftool-0.0.3.dist-info/entry_points.txt,sha256=H3Z3iWsLB1CFdckedIA652_3tWaNS5Rl7fFWgFaFRIc,48
8
- addftool-0.0.3.dist-info/top_level.txt,sha256=jqj56-plrBbyzY0tIxB6wPzjAA8kte4hUlajyyQygN4,9
9
- addftool-0.0.3.dist-info/RECORD,,