addftool 0.0.2__py3-none-any.whl → 0.0.4__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,12 @@
1
1
  import argparse
2
2
  import requests
3
- import subprocess
4
3
  import os
5
4
  import json
6
5
  import yaml
7
6
  from cryptography.fernet import Fernet
8
7
 
8
+ from .util import execute_command
9
+
9
10
 
10
11
  def add_api(parser):
11
12
  parser.add_argument("-k", "--key", help="f key", required=True)
@@ -23,17 +24,6 @@ def get_ubuntu_version():
23
24
  return "22.04"
24
25
 
25
26
 
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
27
  def create_dir_for_current_user(dir_path, sudo=False):
38
28
  command = f"mkdir -p {dir_path}"
39
29
  if sudo:
@@ -45,7 +35,29 @@ def create_dir_for_current_user(dir_path, sudo=False):
45
35
  execute_command(command)
46
36
 
47
37
 
38
+ def check_package_installed(package):
39
+ command = f"dpkg -l | grep {package}"
40
+ result = execute_command(command)
41
+ if result is not None and package in result:
42
+ return True
43
+ return False
44
+
45
+
48
46
  def install_main(args):
47
+
48
+ to_install = []
49
+ for package in args.packages.split():
50
+ if check_package_installed(package):
51
+ print(f"{package} is already installed")
52
+ continue
53
+ to_install.append(package)
54
+
55
+ if len(to_install) == 0:
56
+ print("All packages are already installed")
57
+ return
58
+ else:
59
+ args.packages = " ".join(to_install)
60
+
49
61
  # generate install script
50
62
  if args.output_script is not None:
51
63
  script_writer = open(args.output_script, "w")
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.2
3
+ Version: 0.0.4
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=5gdXzv_8RQOjCEo1ihsP3S3e7nrfqKWwfpxGw7pipXs,6690
3
+ addftool/tool.py,sha256=EuKQ2t2InN7yB-_oYLcdsA7vRqzRGTunwIxplUSqEG0,2054
4
+ addftool/util.py,sha256=Q3A68vJDxgfeNiEFmk54HuMuworVndocXpSbVpvGMfc,362
5
+ addftool-0.0.4.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
6
+ addftool-0.0.4.dist-info/METADATA,sha256=If4J7R9OXA8e0OXs02shLes0NUmSK5pk4hsYyG48qKg,149
7
+ addftool-0.0.4.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
8
+ addftool-0.0.4.dist-info/entry_points.txt,sha256=h5TlQy4AQw-J55HqI7FRkIVRUfw-x3pStFWCoYtoCTM,78
9
+ addftool-0.0.4.dist-info/top_level.txt,sha256=jqj56-plrBbyzY0tIxB6wPzjAA8kte4hUlajyyQygN4,9
10
+ addftool-0.0.4.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=bPtnt0T79jdkMjdJFp_wExvaoxlclbhw9cTw7Iug3rY,6437
3
- addftool/util.py,sha256=gx-pqNJk31tmWtRJvZrIkI15ER7QZg9FtaM_OyP0JqU,975
4
- addftool-0.0.2.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
5
- addftool-0.0.2.dist-info/METADATA,sha256=qv43J1fLZpinNN5oGkExEcoVsDCHAuots7BrWTkw1So,149
6
- addftool-0.0.2.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
7
- addftool-0.0.2.dist-info/entry_points.txt,sha256=H3Z3iWsLB1CFdckedIA652_3tWaNS5Rl7fFWgFaFRIc,48
8
- addftool-0.0.2.dist-info/top_level.txt,sha256=jqj56-plrBbyzY0tIxB6wPzjAA8kte4hUlajyyQygN4,9
9
- addftool-0.0.2.dist-info/RECORD,,