viur-cli 2.2.0__tar.gz → 2.3.0__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.
Files changed (43) hide show
  1. {viur_cli-2.2.0 → viur_cli-2.3.0}/PKG-INFO +54 -7
  2. viur_cli-2.2.0/src/viur_cli.egg-info/PKG-INFO → viur_cli-2.3.0/README.md +46 -22
  3. viur_cli-2.3.0/pyproject.toml +46 -0
  4. viur_cli-2.3.0/setup.cfg +4 -0
  5. viur_cli-2.3.0/src/viur_cli/cli.py +260 -0
  6. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/cloud.py +4 -5
  7. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/conf.py +49 -25
  8. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/local.py +3 -1
  9. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/package.py +5 -5
  10. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/scriptor/cli.py +89 -86
  11. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/setup.py +1 -1
  12. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/utils.py +6 -6
  13. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/version.py +1 -1
  14. viur_cli-2.2.0/README.md → viur_cli-2.3.0/src/viur_cli.egg-info/PKG-INFO +69 -0
  15. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli.egg-info/SOURCES.txt +0 -13
  16. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli.egg-info/requires.txt +3 -1
  17. viur_cli-2.2.0/pyproject.toml +0 -6
  18. viur_cli-2.2.0/setup.cfg +0 -41
  19. viur_cli-2.2.0/setup.py +0 -21
  20. viur_cli-2.2.0/src/viur_cli/cli.py +0 -53
  21. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/__init__.py +0 -53
  22. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/csvwriter.py +0 -129
  23. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/dialog.py +0 -213
  24. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/logger.py +0 -80
  25. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/module.py +0 -169
  26. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/network.py +0 -127
  27. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/progressbar.py +0 -17
  28. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/readers.py +0 -39
  29. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/utils.py +0 -25
  30. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/viur.py +0 -195
  31. viur_cli-2.2.0/src/viur_cli/scriptor/scriptor/writer.py +0 -230
  32. {viur_cli-2.2.0 → viur_cli-2.3.0}/LICENSE +0 -0
  33. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/__init__.py +1 -1
  34. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/build.py +0 -0
  35. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/deprecated.py +0 -0
  36. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/scriptor/__init__.py +0 -0
  37. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/scripts/__init__.py +0 -0
  38. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/scripts/get_pyodide.py +0 -0
  39. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/tool.py +0 -0
  40. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli/update.py +0 -0
  41. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli.egg-info/dependency_links.txt +0 -0
  42. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli.egg-info/entry_points.txt +0 -0
  43. {viur_cli-2.2.0 → viur_cli-2.3.0}/src/viur_cli.egg-info/top_level.txt +0 -0
@@ -1,23 +1,24 @@
1
1
  Metadata-Version: 2.4
2
- Name: viur_cli
3
- Version: 2.2.0
2
+ Name: viur-cli
3
+ Version: 2.3.0
4
4
  Summary: Command-line interface for ViUR application maintenance.
5
- Home-page: https://github.com/viur-framework/viur-cli
6
- Author: Andreas H. Kelch
7
- Author-email: ak@mausbrand.de
5
+ Author-email: "Andreas H. Kelch" <ak@mausbrand.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/viur-framework/viur-cli
8
8
  Project-URL: Bug Tracker, https://github.com/viur-framework/viur-cli/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
- Classifier: License :: OSI Approved :: MIT License
12
11
  Requires-Python: >=3.11
13
12
  Description-Content-Type: text/markdown
14
13
  License-File: LICENSE
15
- Requires-Dist: app_server~=1.0
14
+ Requires-Dist: app-server~=1.0
16
15
  Requires-Dist: click~=8.1.7
17
16
  Requires-Dist: pipfile-requirements~=0.3
18
17
  Requires-Dist: requests~=2.0
19
18
  Requires-Dist: semver~=3.0
20
19
  Requires-Dist: watchdog~=6.0
20
+ Requires-Dist: safety~=3.5
21
+ Requires-Dist: viur-scriptor-api~=1.0
21
22
  Dynamic: license-file
22
23
 
23
24
  <div align="center">
@@ -46,6 +47,52 @@ To use `viur-cli` in your ViUR projects, install the [PyPI package `viur-cli`](h
46
47
  $ pipenv install --dev viur-cli
47
48
  ```
48
49
 
50
+ ## Shell Autocompletion
51
+
52
+ `viur-cli` supports shell autocompletion for bash, zsh, and fish shells. This makes it easier to use the CLI by providing tab-completion for commands and options.
53
+
54
+ ### Installing Autocompletion
55
+
56
+ To install autocompletion for your shell, run:
57
+
58
+ ```bash
59
+ $ viur setup-autocomplete
60
+ ```
61
+
62
+ This will automatically detect your shell and set up the appropriate completion script. You can also specify a shell explicitly:
63
+
64
+ ```bash
65
+ $ viur setup-autocomplete --shell=bash # For bash
66
+ $ viur setup-autocomplete --shell=zsh # For zsh
67
+ $ viur setup-autocomplete --shell=fish # For fish
68
+ ```
69
+
70
+ After installation, restart your shell or source your shell configuration file:
71
+
72
+ ```bash
73
+ # For bash
74
+ $ source ~/.bashrc
75
+
76
+ # For zsh
77
+ $ source ~/.zshrc
78
+ ```
79
+
80
+ ### Checking Autocompletion Status
81
+
82
+ To see if autocompletion is installed and get more information:
83
+
84
+ ```bash
85
+ $ viur autocomplete-info
86
+ ```
87
+
88
+ ### Uninstalling Autocompletion
89
+
90
+ To remove the autocompletion setup:
91
+
92
+ ```bash
93
+ $ viur uninstall-autocomplete
94
+ ```
95
+
49
96
  ## Usage
50
97
 
51
98
  ```sh
@@ -1,25 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: viur_cli
3
- Version: 2.2.0
4
- Summary: Command-line interface for ViUR application maintenance.
5
- Home-page: https://github.com/viur-framework/viur-cli
6
- Author: Andreas H. Kelch
7
- Author-email: ak@mausbrand.de
8
- Project-URL: Bug Tracker, https://github.com/viur-framework/viur-cli/issues
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Operating System :: OS Independent
11
- Classifier: License :: OSI Approved :: MIT License
12
- Requires-Python: >=3.11
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: app_server~=1.0
16
- Requires-Dist: click~=8.1.7
17
- Requires-Dist: pipfile-requirements~=0.3
18
- Requires-Dist: requests~=2.0
19
- Requires-Dist: semver~=3.0
20
- Requires-Dist: watchdog~=6.0
21
- Dynamic: license-file
22
-
23
1
  <div align="center">
24
2
  <img src="https://github.com/viur-framework/viur-artwork/raw/main/icons/icon-cli.svg" height="196" alt="A hexagonal logo of the viur-cli" title="viur-cli">
25
3
  <h1>viur-cli</h1>
@@ -46,6 +24,52 @@ To use `viur-cli` in your ViUR projects, install the [PyPI package `viur-cli`](h
46
24
  $ pipenv install --dev viur-cli
47
25
  ```
48
26
 
27
+ ## Shell Autocompletion
28
+
29
+ `viur-cli` supports shell autocompletion for bash, zsh, and fish shells. This makes it easier to use the CLI by providing tab-completion for commands and options.
30
+
31
+ ### Installing Autocompletion
32
+
33
+ To install autocompletion for your shell, run:
34
+
35
+ ```bash
36
+ $ viur setup-autocomplete
37
+ ```
38
+
39
+ This will automatically detect your shell and set up the appropriate completion script. You can also specify a shell explicitly:
40
+
41
+ ```bash
42
+ $ viur setup-autocomplete --shell=bash # For bash
43
+ $ viur setup-autocomplete --shell=zsh # For zsh
44
+ $ viur setup-autocomplete --shell=fish # For fish
45
+ ```
46
+
47
+ After installation, restart your shell or source your shell configuration file:
48
+
49
+ ```bash
50
+ # For bash
51
+ $ source ~/.bashrc
52
+
53
+ # For zsh
54
+ $ source ~/.zshrc
55
+ ```
56
+
57
+ ### Checking Autocompletion Status
58
+
59
+ To see if autocompletion is installed and get more information:
60
+
61
+ ```bash
62
+ $ viur autocomplete-info
63
+ ```
64
+
65
+ ### Uninstalling Autocompletion
66
+
67
+ To remove the autocompletion setup:
68
+
69
+ ```bash
70
+ $ viur uninstall-autocomplete
71
+ ```
72
+
49
73
  ## Usage
50
74
 
51
75
  ```sh
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=65",
4
+ "wheel"
5
+ ]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+ name = "viur-cli"
10
+ dynamic = ["version"]
11
+ authors = [
12
+ {name = "Andreas H. Kelch", email = "ak@mausbrand.de"}
13
+ ]
14
+ description = "Command-line interface for ViUR application maintenance."
15
+ readme = "README.md"
16
+ requires-python = ">=3.11"
17
+ license = "MIT"
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "Operating System :: OS Independent",
21
+ ]
22
+ dependencies = [
23
+ "app-server~=1.0",
24
+ "click~=8.1.7",
25
+ "pipfile-requirements~=0.3",
26
+ "requests~=2.0",
27
+ "semver~=3.0",
28
+ "watchdog~=6.0",
29
+ "safety~=3.5",
30
+ "viur-scriptor-api~=1.0",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/viur-framework/viur-cli"
35
+ "Bug Tracker" = "https://github.com/viur-framework/viur-cli/issues"
36
+
37
+ [project.scripts]
38
+ viur = "viur_cli:cli"
39
+ get-pyodide = "viur_cli.scripts.get_pyodide:main"
40
+
41
+ [tool.setuptools]
42
+ package-dir = {"" = "src"}
43
+ packages = {find = {where = ["src"]}}
44
+
45
+ [tool.setuptools.dynamic]
46
+ version = {attr = "viur_cli.version.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,260 @@
1
+ import re
2
+ import subprocess
3
+ import click
4
+ from .conf import *
5
+ from .version import __version__
6
+ from .version import MINIMAL_PIPENV
7
+ import semver
8
+ import pprint
9
+ import os
10
+ from pathlib import Path
11
+
12
+
13
+ @click.group(invoke_without_command=True, no_args_is_help=True,
14
+ context_settings={"help_option_names": ["-h", "--help"]})
15
+ @click.version_option(__version__)
16
+ @click.pass_context
17
+ def cli(ctx):
18
+ """
19
+ Command-line interface for managing project configuration and information.
20
+
21
+ The viur-cli provides a set of commands to manage your project's configuration in the 'project.json'.
22
+ It also offers commands to view and modify project information.
23
+
24
+ Note:
25
+
26
+ - Use the `--version` option to display the CLI tool's version.
27
+
28
+ - Run the 'project' command to manage 'project.json' and project configuration settings.
29
+ """
30
+
31
+ # Get the systems pipenv Version Number
32
+ pipenv_version = subprocess.check_output(['pipenv', '--version']).decode("utf-8")
33
+ version_pattern = r'\b(\d+\.\d+\.\d+)\b'
34
+ match = re.search(version_pattern, pipenv_version)
35
+ sys_pipenv = match.group(1)
36
+
37
+ # sys kleiner min
38
+ if semver.compare(sys_pipenv, MINIMAL_PIPENV) < 0:
39
+ echo_warning(
40
+ f"Your pipenv Version does not match the recommended pipenv version. \n"
41
+ f"This mismatch may cause Errors, please consider updating your Systems pipenv version \n"
42
+ f"Your Version: {sys_pipenv}\n"
43
+ f"Recommended Version: {MINIMAL_PIPENV}"
44
+ )
45
+
46
+
47
+ @cli.command()
48
+ @click.argument("action", type=click.Choice(['list']))
49
+ @click.argument("profile", default="default")
50
+ def project(action, profile):
51
+ """List your project.json Configuration File"""
52
+ project_config = config.get_profile(profile)
53
+ if action == "list":
54
+ echo_info(f"These are the Settings for {profile} profile")
55
+ pprint.pprint(project_config)
56
+
57
+
58
+ @cli.command()
59
+ @click.option('--shell', type=click.Choice(['bash', 'zsh', 'fish', 'auto']),
60
+ default='auto', help='Shell type (auto-detect if not specified)')
61
+ def setup_autocomplete(shell):
62
+ """Install shell autocompletion for the viur CLI.
63
+
64
+ This command sets up autocompletion for your shell, making it easier
65
+ to use the viur CLI by providing tab-completion for commands and options.
66
+ """
67
+ # Auto-detect shell if not specified
68
+ if shell == 'auto':
69
+ shell_env = os.environ.get('SHELL', '')
70
+ if 'bash' in shell_env:
71
+ shell = 'bash'
72
+ elif 'zsh' in shell_env:
73
+ shell = 'zsh'
74
+ elif 'fish' in shell_env:
75
+ shell = 'fish'
76
+ else:
77
+ echo_error("Could not auto-detect shell. Please specify with --shell")
78
+ return
79
+
80
+ echo_info(f"Setting up autocompletion for {shell}...")
81
+
82
+ home = Path.home()
83
+
84
+ if shell == 'bash':
85
+ completion_file = home / '.viur-completion.bash'
86
+ rc_file = home / '.bashrc'
87
+
88
+ # Generate completion script
89
+ completion_script = subprocess.run(
90
+ ['viur'],
91
+ env={**os.environ, '_VIUR_COMPLETE': 'bash_source'},
92
+ capture_output=True,
93
+ text=True
94
+ )
95
+
96
+ if completion_script.returncode != 0:
97
+ echo_error("Failed to generate bash completion script")
98
+ return
99
+
100
+ # Write completion script
101
+ completion_file.write_text(completion_script.stdout)
102
+
103
+ # Add to .bashrc if not already present
104
+ source_line = f'source {completion_file}\n'
105
+ if rc_file.exists():
106
+ rc_content = rc_file.read_text()
107
+ if str(completion_file) not in rc_content:
108
+ with rc_file.open('a') as f:
109
+ f.write(f'\n# viur CLI autocompletion\n')
110
+ f.write(source_line)
111
+ echo_success(f"Added autocompletion to {rc_file}")
112
+ else:
113
+ echo_info("Autocompletion already configured in .bashrc")
114
+ else:
115
+ echo_warning(".bashrc not found. Please add the following line manually:")
116
+ echo_info(source_line)
117
+
118
+ elif shell == 'zsh':
119
+ completion_file = home / '.viur-completion.zsh'
120
+ rc_file = home / '.zshrc'
121
+
122
+ # Generate completion script
123
+ completion_script = subprocess.run(
124
+ ['viur'],
125
+ env={**os.environ, '_VIUR_COMPLETE': 'zsh_source'},
126
+ capture_output=True,
127
+ text=True
128
+ )
129
+
130
+ if completion_script.returncode != 0:
131
+ echo_error("Failed to generate zsh completion script")
132
+ return
133
+
134
+ # Write completion script
135
+ completion_file.write_text(completion_script.stdout)
136
+
137
+ # Add to .zshrc if not already present
138
+ source_line = f'source {completion_file}\n'
139
+ if rc_file.exists():
140
+ rc_content = rc_file.read_text()
141
+ if str(completion_file) not in rc_content:
142
+ with rc_file.open('a') as f:
143
+ f.write(f'\n# viur CLI autocompletion\n')
144
+ f.write(source_line)
145
+ echo_success(f"Added autocompletion to {rc_file}")
146
+ else:
147
+ echo_info("Autocompletion already configured in .zshrc")
148
+ else:
149
+ echo_warning(".zshrc not found. Please add the following line manually:")
150
+ echo_info(source_line)
151
+
152
+ elif shell == 'fish':
153
+ completion_dir = home / '.config' / 'fish' / 'completions'
154
+ completion_file = completion_dir / 'viur.fish'
155
+
156
+ # Create directory if it doesn't exist
157
+ completion_dir.mkdir(parents=True, exist_ok=True)
158
+
159
+ # Generate completion script
160
+ completion_script = subprocess.run(
161
+ ['viur'],
162
+ env={**os.environ, '_VIUR_COMPLETE': 'fish_source'},
163
+ capture_output=True,
164
+ text=True
165
+ )
166
+
167
+ if completion_script.returncode != 0:
168
+ echo_error("Failed to generate fish completion script")
169
+ return
170
+
171
+ # Write completion script
172
+ completion_file.write_text(completion_script.stdout)
173
+ echo_success(f"Installed fish completion to {completion_file}")
174
+
175
+ echo_info("\nAutocompletion setup complete!")
176
+ echo_info("Please restart your shell or run:")
177
+ if shell in ['bash', 'zsh']:
178
+ echo_info(f" source {completion_file}")
179
+
180
+
181
+ @cli.command()
182
+ def uninstall_autocomplete():
183
+ """Remove shell autocompletion for the viur CLI."""
184
+ home = Path.home()
185
+ removed = False
186
+
187
+ # Remove completion files
188
+ completion_files = [
189
+ home / '.viur-completion.bash',
190
+ home / '.viur-completion.zsh',
191
+ home / '.config' / 'fish' / 'completions' / 'viur.fish'
192
+ ]
193
+
194
+ for file in completion_files:
195
+ if file.exists():
196
+ file.unlink()
197
+ echo_info(f"Removed {file}")
198
+ removed = True
199
+
200
+ # Clean up shell rc files
201
+ rc_files = [
202
+ (home / '.bashrc', '.viur-completion.bash'),
203
+ (home / '.zshrc', '.viur-completion.zsh')
204
+ ]
205
+
206
+ for rc_file, completion_name in rc_files:
207
+ if rc_file.exists():
208
+ content = rc_file.read_text()
209
+ if completion_name in content:
210
+ # Remove the source line and the comment before it
211
+ lines = content.splitlines()
212
+ new_lines = []
213
+ skip_next = False
214
+
215
+ for i, line in enumerate(lines):
216
+ if '# viur CLI autocompletion' in line:
217
+ skip_next = True
218
+ continue
219
+ if skip_next and completion_name in line:
220
+ skip_next = False
221
+ continue
222
+ new_lines.append(line)
223
+
224
+ rc_file.write_text('\n'.join(new_lines))
225
+ echo_info(f"Cleaned up {rc_file}")
226
+ removed = True
227
+
228
+ if removed:
229
+ echo_success("Autocompletion uninstalled successfully")
230
+ else:
231
+ echo_info("No autocompletion files found")
232
+
233
+
234
+ @cli.command()
235
+ def autocomplete_info():
236
+ """Show autocompletion status and instructions."""
237
+ echo_info("viur CLI Autocompletion Information")
238
+ echo_info("=" * 40)
239
+
240
+ shell = os.environ.get('SHELL', 'unknown')
241
+ echo_info(f"Current shell: {shell}")
242
+
243
+ home = Path.home()
244
+ completion_files = {
245
+ 'bash': home / '.viur-completion.bash',
246
+ 'zsh': home / '.viur-completion.zsh',
247
+ 'fish': home / '.config' / 'fish' / 'completions' / 'viur.fish'
248
+ }
249
+
250
+ installed = []
251
+ for shell_type, file_path in completion_files.items():
252
+ if file_path.exists():
253
+ installed.append(shell_type)
254
+
255
+ if installed:
256
+ echo_success(f"Autocompletion installed for: {', '.join(installed)}")
257
+ else:
258
+ echo_warning("No autocompletion installed")
259
+ echo_info("\nTo install, run:")
260
+ echo_info(" viur setup-autocomplete")
@@ -6,7 +6,7 @@ import string
6
6
  import time
7
7
  import click
8
8
  import yaml
9
- from viur_cli import echo_positive, echo_warning, echo_fatal
9
+ from viur_cli import echo_success, echo_warning, echo_fatal
10
10
  from .conf import config
11
11
  from . import cli, echo_error, echo_info, replace_vars
12
12
  from .update import create_req
@@ -305,7 +305,7 @@ def gcloud_get_roles(profile):
305
305
  with open(json_file_path, 'w') as json_file:
306
306
  json.dump(usable_dict, json_file, indent=4)
307
307
 
308
- echo_positive(f"You can now watch your gcloud Roles Setup in your '{json_file_path}' file ")
308
+ echo_success(f"You can now watch your gcloud Roles Setup in your '{json_file_path}' file ")
309
309
 
310
310
  except yaml.YAMLError as e:
311
311
  echo_error(f"An error occurred during YAML to Dictionary transformation: {e}")
@@ -455,7 +455,7 @@ def deploy(action, profile, name, ext, yes, skip_checks: bool, additional_args):
455
455
  return
456
456
  else:
457
457
  echo_info("\U00002714 No vulnerabilities found.")
458
-
458
+
459
459
  version = replace_vars(
460
460
  conf["version"],
461
461
  {k: v for k, v in conf.items() if k not in ["version"]}
@@ -697,6 +697,5 @@ def create(profile, action, gen, source, name, entrypoint, env_vars_file, memory
697
697
 
698
698
  config[profile] = conf
699
699
  config.migrate()
700
- echo_positive("Your cloud function creation was successful, if you want to add more flags, "
700
+ echo_success("Your cloud function creation was successful, if you want to add more flags, "
701
701
  "add them in your project.json")
702
-
@@ -6,18 +6,13 @@ from .utils import *
6
6
  from .version import __version__ as cli_version
7
7
 
8
8
 
9
- PROJECT_CONFIG_FILE = "project.json"
10
- PROJECT_CONFIG_VERSION = "2.0.0"
11
- LAST_VERSION = ""
9
+ class Config(dict):
10
+ CONFIG_FILE = None
11
+ PROJECT_CONFIG_VERSION = None
12
+ LAST_VERSION = None
12
13
 
13
-
14
- class ProjectConfig(dict):
15
-
16
- def __init__(self):
17
- super().__init__()
18
- self["default"] = {}
19
- self["format"] = PROJECT_CONFIG_VERSION
20
- self.initial_load = False
14
+ def __init__(self, *args, **kwargs):
15
+ self.load()
21
16
 
22
17
  def load(self):
23
18
  """
@@ -34,48 +29,59 @@ class ProjectConfig(dict):
34
29
  :return: dict
35
30
  The project configuration loaded from the project.json file.
36
31
  """
37
-
38
32
  # Search in any parent folder for a project.json,
39
33
  # change working directory because subsequent commands
40
34
  # require for project root folder.
35
+
41
36
  changed = False
42
- while not os.path.exists(PROJECT_CONFIG_FILE):
37
+ while not os.path.exists(self.CONFIG_FILE):
43
38
  os.chdir("..")
44
39
  changed = True
45
40
 
46
41
  if os.getcwd() == "/":
47
- echo_fatal(f"{PROJECT_CONFIG_FILE} not found - please check if you are in the right folder.")
42
+ echo_fatal(f"{self.CONFIG_FILE} not found - please check if you are in the right folder.")
48
43
 
49
44
  if changed:
50
45
  echo_info(f"Project root is {os.getcwd()}")
51
46
 
52
47
  try:
53
- f = open(PROJECT_CONFIG_FILE, "r")
48
+ f = open(self.CONFIG_FILE, "r")
54
49
  self.update(json.loads(f.read()))
55
50
 
51
+
56
52
  except FileNotFoundError:
57
- echo_fatal(f"Can't open {PROJECT_CONFIG_FILE} for reading")
53
+ echo_fatal(f"Can't open {self.CONFIG_FILE} for reading")
58
54
 
59
55
  except json.decoder.JSONDecodeError as e:
60
56
  echo_fatal(
61
- f"The configuration in {PROJECT_CONFIG_FILE} contains invalid JSON: {str(e)}. Please verify right syntax.")
62
-
57
+ f"The configuration in {self.CONFIG_FILE} contains invalid JSON: {str(e)}. Please verify right syntax.")
63
58
  self.migrate()
64
59
 
60
+ def migrate(self):
61
+ pass
62
+
65
63
  def save(self):
66
64
  """
67
65
  Write the current projectConfig dictionary to project.json.
68
66
  """
69
- with open(PROJECT_CONFIG_FILE, "w") as f:
67
+ with open(self.CONFIG_FILE, "w") as f:
70
68
  json.dump(self, f, indent=4, sort_keys=True)
71
69
  f.write('\n')
72
70
 
71
+
72
+ class ProjectConfig(Config):
73
+ CONFIG_FILE = "project.json"
74
+ PROJECT_CONFIG_VERSION = "2.0.0"
75
+ LAST_VERSION = ""
76
+
77
+ def __init__(self):
78
+
79
+ self["default"] = {}
80
+ self["format"] = self.PROJECT_CONFIG_VERSION
81
+ super().__init__()
82
+
73
83
  def get_profile(self, profile):
74
84
  """Get profile configuration"""
75
- if not self.initial_load:
76
- self.load()
77
- self.initial_load = True
78
-
79
85
  if profile == "format":
80
86
  echo_fatal("Your profile can not be named 'Format' ")
81
87
  if profile not in self:
@@ -95,7 +101,6 @@ class ProjectConfig(dict):
95
101
  else:
96
102
  for value in list(dictionary.values()):
97
103
  if isinstance(value, dict):
98
-
99
104
  self.find_key(value, target_key, target, keep=keep)
100
105
 
101
106
  def remove_key(self, dictionary, target_key):
@@ -124,7 +129,7 @@ class ProjectConfig(dict):
124
129
  self["format"] = old_format
125
130
  del self["default"]["format"]
126
131
 
127
- assert self["format"] in ["1.0.0", "1.0.1", "1.1.0", "1.1.1", "1.2.0", PROJECT_CONFIG_VERSION], \
132
+ assert self["format"] in ["1.0.0", "1.0.1", "1.1.0", "1.1.1", "1.2.0", self.PROJECT_CONFIG_VERSION], \
128
133
  "Invalid formatversion, you have to fix it manually"
129
134
 
130
135
  # Version 1.0.1
@@ -219,4 +224,23 @@ def get_changelog_difference(response, response1):
219
224
  echo_info(line[1:])
220
225
 
221
226
 
227
+ class ScriptorConfig(Config):
228
+ """
229
+ Manage scriptor configuration.
230
+ TODO miragte with other config
231
+ """
232
+ CONFIG_FILE = "viur_scriptor_config.json"
233
+ DEFAULT_BASE_URL = "http://localhost:8080"
234
+ DEFAULT_WORKING_DIR = "scripts/"
235
+ _instance = None
236
+
237
+ def __init__(self, *args, **kwargs):
238
+ self.update({
239
+ "base_url": self.DEFAULT_BASE_URL,
240
+ "working_dir": self.DEFAULT_WORKING_DIR,
241
+ })
242
+ super().__init__(*args, **kwargs)
243
+
244
+
222
245
  config = ProjectConfig()
246
+ scriptor_config = ScriptorConfig()
@@ -48,11 +48,13 @@ def run(profile, additional_args):
48
48
  conf = config.get_profile(profile)
49
49
  additional_args = list(additional_args)
50
50
 
51
+ if appyaml := conf.get("appyaml"):
52
+ additional_args.append(f"--appyaml={appyaml}")
51
53
  if conf.get("port"):
52
54
  additional_args.append(f"--port={conf['port']}")
53
55
  if conf.get("gunicorn_port"):
54
56
  additional_args.append(f"--gunicorn_port={conf['gunicorn_port']}")
55
-
57
+
56
58
  utils.system(
57
59
  f'app_server -A={conf["application_name"]} {conf["distribution_folder"]} {" ".join(additional_args)}')
58
60