-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
244 lines (215 loc) · 8.24 KB
/
constants.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
"""contains ConfigurationFile, BranchSearchResults, Constants, Messages classes"""
# pylint: disable=too-few-public-methods
class ConfigurationFile:
"""represents a config file"""
def __init__(self, filename: str) -> None:
self.__filename = filename
# pylint: disable=missing-function-docstring
def filename(self) -> str:
return self.__filename
# pylint: disable=missing-function-docstring
def config_key(self) -> str:
return self.__filename.split(".")[0]
class RegexSearchPattern:
"""represents a regex search"""
def __init__(self, name, pattern) -> None:
self.name = name
self.pattern = pattern
def __repr__(self) -> str:
return f"{self.name} - {self.pattern}"
# pylint: disable=too-few-public-methods
class BranchSearchResults:
"""represents results of branch search"""
def __init__(self) -> None:
self.matches = {}
self.errors = []
self.skipped_folders = []
self.skipped_files = []
self.folders = []
self.files = []
# pylint: disable=missing-class-docstring
class Constants:
# general
TAB = "\t"
NEWLINE = "\n"
ENCODING = "utf-8"
CONFIG_COMMENT_PREFIX = "#"
COMMENT_PREFIXES = ("#", "//")
WILDCARD = "*"
# ENCODED_SPACE = "%20"
# search patterns
NO_PATTERN = RegexSearchPattern("no pattern", "{word}")
DB_TABLE_PATTERN = RegexSearchPattern(
"database table pattern", "(?<![a-z0-9_]){word}(?![a-z0-9_])"
)
# numbers
DEFAULT_TIME = -1
SECONDS_IN_DAY = 86400
TIMEOUT = 5
RETRIES = 5
SUCCESS_CODE = 200
JSON_INDENT = 4
MAX_PREVIEW_LENGTH = 5000
# folders
CONFIG_FOLDER = "config"
REPOS_FOLDER = "repos"
RESULTS_FOLDER = "results"
# files
ADO_CONFIG_FILE = "ado.toml"
LOG_FILE = "program.log"
CONFIG_FILE = "config.txt"
DETAILS_FILE = "details.txt"
MATCHES_FILE = "matches.txt"
FOUND_FILE = "found.txt"
# ConfigFile objects
REPO_DATA_FILE = ConfigurationFile("repo_data.json")
WORDS_FILE = ConfigurationFile("words.txt")
BRANCH_UPDATES_FILE = ConfigurationFile("branch_updates.json")
EXCLUDE_FILES_FILE = ConfigurationFile("exclude_files.txt")
EXCLUDE_FOLDERS_FILE = ConfigurationFile("exclude_folders.txt")
INCLUDE_REPOS_FILE = ConfigurationFile("include_repos.txt")
EXCLUDE_REPOS_FILE = ConfigurationFile("exclude_repos.txt")
# config keys
TEMPLATE_KEY = "template"
PATTERN_KEY = "pattern"
OFFLINE_KEY = "offline"
TOKEN_KEY = "token"
ORG_KEY = "organization"
PROJECT_KEY = "project"
TARGET_REPOS_KEY = "target_repos"
REPOS_KEY = "repos"
# repo data keys
LAST_UPDATE_KEY = "lastUpdate"
VALUE_KEY = "value"
DEFAULT_BRANCH_KEY = "defaultBranch"
BRANCHES_KEY = "branches"
NAME_KEY = "name"
COUNT_KEY = "count"
ID_KEY = "id"
REMOTE_URL_KEY = "remoteUrl"
# ADO - learn.microsoft.com/en-us/rest/api/azure/devops/git/?view=azure-devops-rest-7.0
BASE_URL = "https://dev.azure.com/"
__API_PREFIX = "{org}/{project}/_apis/git/repositories"
__API_POSTFIX = "api-version=7.0"
REPOS_URL = BASE_URL + __API_PREFIX + "?" + __API_POSTFIX
BRANCHES_URL = BASE_URL + __API_PREFIX + "/{id}/refs?filter=heads/&" + __API_POSTFIX
BRANCH_PREFIX = "refs/heads/"
REPO_URL = "https://{token}@dev.azure.com/{org}/{project}/_git/{name}"
# pylint: disable=missing-class-docstring
class Messages:
## config manager
UNHANDLED_TYPE = "unhandled config type - {type}"
CONFIG_ITEM_NOT_FOUND = "config item doesn't exist (key-{key}, type-{type})"
## config handler
# load template
SELECT_REPO_TEMPLATE = "select a repo search template for initialization"
SELECT_BRANCH_TEMPLATE = "select a branch search template for initialization"
TEMPLATE = "search template - {template}"
MODIFY_TEMPLATE = "include/exclude files will be used to modify this template"
NONE = "None"
ALL = "All"
DEFAULT = "Default"
TEMPLATE_NONE = "no repos"
TEMPLATE_DEFAULT = "all repos, default branch"
TEMPLATE_ALL = "all repos, all branches"
# get input
ENTER_VALID_INTEGER = "enter a valid integer: "
VALUE_ENTERED = "entered - {val}"
INVALID_INTEGER = "invalid, please try again"
KEYBOARD_INTERRUPT = "keyboard interrupt"
# load regex pattern
SELECT_REGEX_PATTERN = "select a regex pattern or specify your own"
CUSTOM_PATTERN = "custom pattern"
ENTER_REGEX_PATTERN = "enter a regex pattern containing {word}"
ENTER_VALID_PATTERN = "enter a valid pattern: "
PATTERN = "regex pattern - {pattern}"
# get connection status
CONNECTION_FAILED = "connection failed"
CONNECTION_STATUS = "offline - {offline}"
# populate config
ADO_CONFIG_SKIP = "skipping loading of ADO config info"
LOCAL_REPO_DATA = "will attempt to use local repo data"
# read file
FILE_NOT_FOUND = "file not found - {path}"
# load ado config
ADO_CONFIG_REQUIRED = "ADO config info (token, organization, project) is required"
BAD_TOML = "ADO config file not configured correctly"
MISSING_INFO = "ADO config file missing info"
# create repo data
REPO_DATA_OK = "repo data exists and was updated within the last day"
REPO_DATA_ISSUE = "repo data either doesn't exist or requires update"
GETTING_REPO_DATA = "getting repo data"
REPOS_MAX_RETRIES = "max retries requesting repo data"
BAD_JSON = "badly formed json response"
# make request
REQUEST_FAILED = "request failed, trying again"
# add branch info
NO_DEFAULT = "{repo} has no default branch - most likely empty"
GETTING_BRANCH_DATA = "getting branch data for {repo} ({pos}/{total})"
BRANCH_MAX_RETRIES = "max retries requesting branch data, skipping"
# write repo data
PARSING_FAILED = "error parsing repo data"
# load search words
NO_WORDS = "no search words - program will be used to update local files"
# load branch timestamps
PARSING_FAILED = "parsing branch updates failed"
# load repo data
NO_REPO_DATA = "repo data file does not exist"
# create target repos
UNKNOWN_TEMPLATE = "unexpected template value - {template}"
# add included repos
BAD_REPO = "invalid repo - {repo}"
BAD_BRANCH = "invalid branch - {branch} ({repo})"
DEFAULT_BRANCH = "including default branch ({branch}) for {repo}"
ALL_BRANCHES = "including all branches of {repo}"
ONE_BRANCH = "including {branch} of {repo}"
# remove excluded repos
REPO_EXCLUDED = "repo {repo} is already not included"
BRANCH_EXCLUDED = "branch {branch} of {repo} is already not included"
EXCLUDING_ALL = "excluding all branches of {repo}"
EXCLUDING_BRANCH = "excluding {branch} of {repo}"
# create repos
NO_URL = "url not found for {repo}"
## logging manager
DEBUG_MSG = "debug - {msg}"
INFO_MSG = "info - {msg}"
ERR_MSG = "error - {msg}"
CRIT_MSG = "critical - {msg}"
EXITING = "exiting..."
WARN_MSG = "warning - {msg}"
## repository
STR = "{repo} - {branches}, {path}"
PATH_EXISTS = "branch path exists"
PATH_DOESNT_EXIST = "branch path does not exist"
INTERVAL = 1
RETRYING = f"trying again in {INTERVAL}s"
GIT_MAX_RETRIES = "max retries for {mode}"
GIT_SUCCESS = "{mode} success"
GIT_FAILURE = "{mode} failed - {err}"
PULL = "pull"
CLONE = "clone"
URL_NOT_SPECIFIED = "repo url not specified"
## searcher
SEARCHING = "starting search"
SEARCHING_REPO = "repo {idx}/{total} - {name}"
SEARCHING_BRANCH = "branch {idx}/{total} - {name}"
UPDATE_NEEDED = "update required"
UPDATE_FAILED = "update failed"
UP_TO_DATE = "updated less than 1 day ago"
NO_LOCAL = "branch files not locally available"
NO_SEARCH = "no search words"
BAD_PATH = "path does not exist"
FILE = "file - {path}"
LINE_TOO_LONG = "LINE TOO LONG - look at file"
LINE = "line {idx} - {line}"
MATCH = "match - {word} - {line}"
PATH_TOO_LONG = "file not found - path too long? - {path}"
DECODING_SUCCESS = "decoding success - {path}"
DECODING_FAILED = "decoding failure - {path}"
## writer
MATCHES = "Matches"
ERRORS = "Errors"
SKIPPED_FOLDERS = "Skipped folders"
SKIPPED_FILES = "Skipped files"
SEARCHED_FOLDERS = "Searched folders"
SEARCHED_FILES = "Searched files"