-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
265 lines (213 loc) · 8.33 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
"""
=====================CAUTION=======================
DO NOT DELETE THIS FILE SINCE IT IS PART OF NROBO
FRAMEWORK AND IT MAY CHANGE IN THE FUTURE UPGRADES
OF NROBO FRAMEWORK. THUS, TO BE ABLE TO SAFELY UPGRADE
TO LATEST NROBO VERSION, PLEASE DO NOT DELETE THIS
FILE OR ALTER ITS LOCATION OR ALTER ITS CONTENT!!!
===================================================
nrobo module loads nRoBo globals.
@author: Panchdev Singh Chauhan
@email: erpanchdev@gmail.com
"""
__version__ = '2024.30.2'
# install rich library
import os
from pathlib import Path
class NROBO_CONST:
"""nrobo special constants"""
NROBO = "nrobo"
DIST_DIR = "dist"
SUCCESS = 0
class Python:
"""Information related to python"""
PIP = "pip"
VERSION = "Version"
PYPINFO = "pypinfo"
class Environment:
"""Environments"""
PRODUCTION = "Production"
DEVELOPMENT = "Development"
class EnvKeys:
"""nRoBo environment keys
Example:
PIP_COMMAND = pip | pip3
and many more such...
"""
APPIUM = "appium"
PIP_COMMAND = "Pip Command"
EXEC_DIR = "Execution Directory"
NROBO_DIR = "nRoBo Installation Directory"
ENVIRONMENT = "Environment"
PYTHON = "Python"
APP = "App Name"
URL = "App Url"
USERNAME = "Username"
PASSWORD = "Password"
TITLE = "Title"
BROWSER = "Browser"
HOST_PLATFORM = "Host Platform"
DEBUG = "debug mode"
SUPPRESS_PROMPT = "suppress prompt"
# load environment keys with defaults
os.environ[EnvKeys.APPIUM] = "0"
os.environ[EnvKeys.PIP_COMMAND] = Python.PIP
os.environ[EnvKeys.EXEC_DIR] = ""
os.environ[EnvKeys.NROBO_DIR] = ""
os.environ[EnvKeys.ENVIRONMENT] = Environment.PRODUCTION
os.environ[EnvKeys.PYTHON] = "python"
os.environ[EnvKeys.APP] = "nRoBo"
os.environ[EnvKeys.URL] = ""
os.environ[EnvKeys.USERNAME] = ""
os.environ[EnvKeys.PASSWORD] = ""
os.environ[EnvKeys.TITLE] = ""
os.environ[EnvKeys.BROWSER] = ""
os.environ[EnvKeys.HOST_PLATFORM] = ""
os.environ[EnvKeys.DEBUG] = "False"
os.environ[EnvKeys.SUPPRESS_PROMPT] = "0"
class NROBO_PATHS:
"""nRoBo framework directories and files"""
EXEC_DIR = Path(os.environ[EnvKeys.EXEC_DIR])
NROBO_DIR = Path(os.environ[EnvKeys.NROBO_DIR])
NODE_MODULES = Path("node_modules")
PATCHES = Path("patches")
NROBO = Path("nrobo")
INIT_PY = Path("__init__.py")
APPIUM = Path("appium")
BROWSER_CONFIGS = Path("browserConfigs")
CAPABILITY_YAML = BROWSER_CONFIGS / "capability.yaml"
CAPABILITY_APPIUM_ANDROID_YAML = APPIUM / "android_capability.yaml"
CAPABILITY_APPIUM_IOS_YAML = APPIUM / "ios_capability.yaml"
MARKERS_YAML = BROWSER_CONFIGS / "markers.yaml"
# Browsers packages
BROWSERS = Path("browsers")
CHROME = Path("chrome")
BROWSERS_CHROME_PKG = BROWSERS / CHROME
EDGE = Path("edge")
BROWSERS_EDGE_PKG = BROWSERS / EDGE
FIREFOX = Path("firefox")
BROWSERS_FIREFOX_PKG = BROWSERS / FIREFOX
SAFARI = Path("safari")
BROWSERS_SAFARI_PKG = BROWSERS / SAFARI
# cli packages
CLI = Path("cli")
CLI_PKG = CLI / INIT_PY
DETECTION = Path("detection")
DETECTION_PKG = CLI / DETECTION / INIT_PY
FORMATTING = Path("formatting")
FORMATTING_PKG = CLI / FORMATTING / INIT_PY
INSTALL = Path("install")
INSTALL_PKG = CLI / INSTALL / INIT_PY
NCODES = Path("ncodes")
NCODES_PKG = CLI / NCODES / INIT_PY
REQUIREMENTS_TXT_FILE = CLI / INSTALL / Path("requirements.txt")
CLI_NROBO_ARGS = Path("nrobo_args")
CLI_NROBO_ARGS_PKG = CLI / CLI_NROBO_ARGS / INIT_PY
CLI_TOOLS = Path("tools")
CLI_TOOLS_PKG = CLI / CLI_TOOLS / INIT_PY
UPGRADE = Path("upgrade")
UPGRADE_PKG = CLI / UPGRADE / INIT_PY
CLI_LAUNCHER_PY_FILE = CLI / Path("launcher.py")
CLI_CONSTANTS_PY_FILE = CLI / Path("cli_constants.py")
CLI_VERSION_YAML_FILE = CLI / Path("cli_version.yaml")
NGLOBALS_PY_FILE = CLI / Path("nglobals.py")
EXCEPTIONS = Path("exceptions")
# framework packages
FRAMEWORK = Path("framework")
PAGES = Path("pages")
FRAMEWORK_PAGES = FRAMEWORK / PAGES
FRAMEWORK_PAGE_PYPI_HOME_PY_FILE = FRAMEWORK_PAGES / Path("PagePyPiHome.py")
TESTS = Path("tests")
MOBILE = Path("mobile")
WEB = Path("web")
FRAMEWORK_TESTS = FRAMEWORK / TESTS
GUI = FRAMEWORK_TESTS / WEB / Path("gui")
GUI_PKG = GUI / INIT_PY
GUI_PYPI_HOME_PAGE_TEST_PY_FILE = GUI / Path("PyPi_home_page_test.py")
NO_GUI_PKG = TESTS / WEB / "no_gui" / INIT_PY
FRAMEWORK_TESTS = FRAMEWORK / TESTS
NROBO_CONFIG_FILE = Path("nrobo-config.yaml")
FRAMEWORK_NROBO_CONFIG = FRAMEWORK / NROBO_CONFIG_FILE
NROBO_CONFTEST_HOST_FILE = FRAMEWORK / "conftest-host.py"
SELENESE = Path("selenese")
# nrobo.util packages
UTIL = Path("util")
COMMANDS = Path("commands")
NCOMMANDS = Path("ncommands")
POSIX = Path("posix")
WINDOWS = Path("windows")
UTIL_NCOMMANDS_PKG = NROBO / UTIL / COMMANDS / NCOMMANDS / INIT_PY
UTIL_POSIX_PKG = NROBO / UTIL / COMMANDS / POSIX / INIT_PY
UTIL_WINDOWS_PKG = NROBO / UTIL / COMMANDS / WINDOWS / INIT_PY
UTIL_COMMON = Path("common")
UTIL_COMMON_PKG = NROBO / UTIL / UTIL_COMMON / INIT_PY
UTIL_CONSTANT = Path("constants")
UTIL_CONSTANT_PKG = NROBO / UTIL / UTIL_CONSTANT / INIT_PY
UTIL_FILESYSTEM = Path("filesystem")
UTIL_FILESYSTEM_PKG = NROBO / UTIL / UTIL_FILESYSTEM / INIT_PY
UTIL_PLATFORM = Path("platform")
UTIL_NETWORK = Path("network")
UTIL_NETWORK_PKG = NROBO / UTIL / UTIL_NETWORK / INIT_PY
UTIL_PLATFORM_PKG = NROBO / UTIL / UTIL_PLATFORM / INIT_PY
UTIL_PROCESS = Path("process")
UTIL_PROCESS_PKG = NROBO / UTIL / UTIL_PROCESS / INIT_PY
UTIL_PYTHON = Path("python")
UTIL_PYTHON_PKG = NROBO / UTIL / UTIL_PYTHON / INIT_PY
UTIL_REGEX = Path("regex")
UTIL_REGEX_PKG = NROBO / UTIL / UTIL_REGEX / INIT_PY
UTIL_VERSION = Path("version")
UTIL_VERSION_PKG = NROBO / UTIL / UTIL_VERSION / INIT_PY
CONFTEST_PY = Path("conftest.py")
NROBO_FRAMEWORK_TESTS = Path("framework_tests")
TESTS = Path("tests")
VERSIONS = Path("versions")
PROD_YAML = VERSIONS / Path("prod.yaml")
TEST_YAML = VERSIONS / Path("test.yaml")
NROBO_PY_FILE = Path("nrobo.py")
PACKAGE_PY_FILE = Path("package.py")
LICENSE_FILE = Path("LICENSE")
PY_PROJECT_TOML_FILE = Path("pyproject.toml")
README_RST_FILE = Path("README.rst")
VALIDATE_NROBO_PY_FILE = Path("validatenrobo.py")
PYTEST_LIFE_CYCLE_LOGS = Path("key") / "experiments" / "pytest" / "pytest-life-cycle-logs"
class NROBO_CLI_TOOL_PATH:
"""nRoBo CLI tool paths"""
CLI = Path("cli")
BUILD = CLI / Path("build")
CHECK = CLI / Path("check")
COMPILE = CLI / Path("compile")
DEVELOPMENT = CLI / Path("development")
PUBLISH = CLI / Path("publish")
class NROBO_FRAMEWORK_TESTS:
"""nrobo_framework_tests package"""
NROBO_FRAMEWORK_TESTS_CONFTEST_PY_FILE = NROBO_PATHS.NROBO_FRAMEWORK_TESTS / NROBO_PATHS.CONFTEST_PY
TEST_NROBO_FRAMEWORK_PY_FILE = NROBO_PATHS.NROBO_FRAMEWORK_TESTS / Path("test_package_presence.py")
import subprocess
from nrobo.util.process import terminal
terminal(["pip", "install", "rich"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
from pathlib import Path
import re
from rich.console import Console
from nrobo.cli.formatting import themes as th, STYLE
from nrobo.util.constants import CONST
# rich console
console = Console(theme=th)
def greet_the_guest():
"""greet the guest with Indian way of greeting!"""
greet_msg = 'Namastey World! Thank you for choosing, nRoBo.'
formatted_heart_string = CONST.HEART_RED * len(greet_msg)
console.print(f'[{STYLE.HLRed}]{formatted_heart_string}')
console.print(f"[{STYLE.HLOrange}]{greet_msg}[/]")
console.print(f'[{STYLE.HLRed}]{formatted_heart_string}')
def set_environment() -> None:
"""set nrobo environment
Not complete implementation as the name suggests.
This implementation will be corrected in future versions..."""
# get directory from where the script was executed
os.environ[EnvKeys.EXEC_DIR] = os.getcwd()
# get directory where this script resides
nrobo_loader_file_path = os.path.dirname(os.path.realpath(__file__))
# grab nrobo installation path
os.environ[EnvKeys.NROBO_DIR] = re.findall(f"(.*{NROBO_CONST.NROBO})", str(nrobo_loader_file_path))[0]
NROBO_PATHS.EXEC_DIR = Path(os.environ[EnvKeys.EXEC_DIR])
NROBO_PATHS.NROBO_DIR = Path(os.environ[EnvKeys.NROBO_DIR])