| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2b3e769 commit 79a36a5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,12 +60,19 @@ def _init_externals(): | |||
| 60 | 60 | ||
| 61 | 61 | ||
| 62 | 62 | #{ Initialize git executable path | |
| 63 | + GIT_OK = None | ||
| 64 | + | ||
| 63 | 65 | def refresh(path=None): | |
| 64 | 66 | """Convenience method for setting the git executable path.""" | |
| 67 | + global GIT_OK | ||
| 68 | + GIT_OK = False | ||
| 69 | + | ||
| 65 | 70 | if not Git.refresh(path=path): | |
| 66 | 71 | return | |
| 67 | 72 | if not FetchInfo.refresh(): | |
| 68 | 73 | return | |
| 74 | + | ||
| 75 | + GIT_OK = True | ||
| 69 | 76 | #} END initialize git executable path | |
| 70 | 77 | ||
| 71 | 78 | ################# | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,13 +191,15 @@ def __setstate__(self, d): | |||
| 191 | 191 | ||
| 192 | 192 | # Provide the full path to the git executable. Otherwise it assumes git is in the path | |
| 193 | 193 | _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE" | |
| 194 | + _refresh_env_var = "GIT_PYTHON_REFRESH" | ||
| 194 | 195 | GIT_PYTHON_GIT_EXECUTABLE = None | |
| 195 | 196 | # note that the git executable is actually found during the refresh step in | |
| 196 | 197 | # the top level __init__ | |
| 197 | 198 | ||
| 198 | 199 | @classmethod | |
| 199 | 200 | def refresh(cls, path=None): | |
| 200 | - """This gets called by the refresh function (see the top level __init__). | ||
| 201 | + """This gets called by the refresh function (see the top level | ||
| 202 | + __init__). | ||
| 201 | 203 | """ | |
| 202 | 204 | # discern which path to refresh with | |
| 203 | 205 | if path is not None: | |
@@ -214,17 +216,21 @@ def refresh(cls, path=None): | |||
| 214 | 216 | try: | |
| 215 | 217 | cls().version() | |
| 216 | 218 | has_git = True | |
| 217 | - except GitCommandNotFound: | ||
| 219 | + except (GitCommandNotFound, PermissionError): | ||
| 220 | + # - a GitCommandNotFound error is spawned by ourselves | ||
| 221 | + # - a PermissionError is spawned if the git executable provided | ||
| 222 | + # cannot be executed for whatever reason | ||
| 218 | 223 | pass | |
| 219 | 224 | ||
| 220 | 225 | # warn or raise exception if test failed | |
| 221 | 226 | if not has_git: | |
| 222 | 227 | err = dedent("""\ | |
| 223 | - Bad git executable. The git executable must be specified in one of the following ways: | ||
| 224 | - (1) be included in your $PATH, or | ||
| 225 | - (2) be set via $GIT_PYTHON_GIT_EXECUTABLE, or | ||
| 226 | - (3) explicitly set via git.refresh. | ||
| 227 | - """) | ||
| 228 | + Bad git executable. | ||
| 229 | + The git executable must be specified in one of the following ways: | ||
| 230 | + - be included in your $PATH | ||
| 231 | + - be set via $%s | ||
| 232 | + - explicitly set via git.refresh() | ||
| 233 | + """) % cls._git_exec_env_var | ||
| 228 | 234 | ||
| 229 | 235 | # revert to whatever the old_git was | |
| 230 | 236 | cls.GIT_PYTHON_GIT_EXECUTABLE = old_git | |
@@ -241,36 +247,53 @@ def refresh(cls, path=None): | |||
| 241 | 247 | # 1|w|warn|warning | |
| 242 | 248 | # 2|r|raise|e|error | |
| 243 | 249 | ||
| 244 | - mode = os.environ.get("GIT_PYTHON_REFRESH", "raise").lower() | ||
| 250 | + mode = os.environ.get(cls._refresh_env_var, "raise").lower() | ||
| 245 | 251 | ||
| 246 | - quiet = ["0", "q", "quiet", "s", "silence", "n", "none"] | ||
| 247 | - warn = ["1", "w", "warn", "warning"] | ||
| 248 | - error = ["2", "e", "error", "r", "raise"] | ||
| 252 | + quiet = ["quiet", "q", "silence", "s", "none", "n", "0"] | ||
| 253 | + warn = ["warn", "w", "warning", "1"] | ||
| 254 | + error = ["error", "e", "raise", "r", "2"] | ||
| 249 | 255 | ||
| 250 | 256 | if mode in quiet: | |
| 251 | 257 | pass | |
| 252 | - elif mode in warn: | ||
| 253 | - print(dedent("""\ | ||
| 254 | - WARNING: %s | ||
| 258 | + elif mode in warn or mode in error: | ||
| 259 | + err = dedent("""\ | ||
| 260 | + %s | ||
| 255 | 261 | All git commands will error until this is rectified. | |
| 256 | 262 | ||
| 257 | - This initial warning can be silenced in the future by setting the environment variable: | ||
| 258 | - export GIT_PYTHON_REFRESH=quiet | ||
| 259 | - """) % err) | ||
| 260 | - elif mode in error: | ||
| 261 | - raise ImportError(err) | ||
| 263 | + This initial warning can be silenced or aggravated in the future by setting the | ||
| 264 | + $%s environment variable. Use one of the following values: | ||
| 265 | + - %s: for no warning or exception | ||
| 266 | + - %s: for a printed warning | ||
| 267 | + - %s: for a raised exception | ||
| 268 | + | ||
| 269 | + Example: | ||
| 270 | + export %s=%s | ||
| 271 | + """) % ( | ||
| 272 | + err, | ||
| 273 | + cls._refresh_env_var, | ||
| 274 | + "|".join(quiet), | ||
| 275 | + "|".join(warn), | ||
| 276 | + "|".join(error), | ||
| 277 | + cls._refresh_env_var, | ||
| 278 | + quiet[0]) | ||
| 279 | + | ||
| 280 | + if mode in warn: | ||
| 281 | + print("WARNING: %s" % err) | ||
| 282 | + else: | ||
| 283 | + raise ImportError(err) | ||
| 262 | 284 | else: | |
| 263 | 285 | err = dedent("""\ | |
| 264 | - GIT_PYTHON_REFRESH environment variable has been set but it has been set with an invalid value. | ||
| 286 | + %s environment variable has been set but it has been set with an invalid value. | ||
| 265 | 287 | ||
| 266 | 288 | Use only the following values: | |
| 267 | - (1) {quiet}: for no warning or exception | ||
| 268 | - (2) {warn}: for a printed warning | ||
| 269 | - (3) {error}: for a raised exception | ||
| 270 | - """).format( | ||
| 271 | - quiet="|".join(quiet), | ||
| 272 | - warn="|".join(warn), | ||
| 273 | - error="|".join(error)) | ||
| 289 | + - %s: for no warning or exception | ||
| 290 | + - %s: for a printed warning | ||
| 291 | + - %s: for a raised exception | ||
| 292 | + """) % ( | ||
| 293 | + cls._refresh_env_var, | ||
| 294 | + "|".join(quiet), | ||
| 295 | + "|".join(warn), | ||
| 296 | + "|".join(error)) | ||
| 274 | 297 | raise ImportError(err) | |
| 275 | 298 | ||
| 276 | 299 | # we get here if this was the init refresh and the refresh mode | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,7 +221,8 @@ class FetchInfo(object): | |||
| 221 | 221 | ||
| 222 | 222 | @classmethod | |
| 223 | 223 | def refresh(cls): | |
| 224 | - """This gets called by the setup function (see the top level __init__). | ||
| 224 | + """This gets called by the refresh function (see the top level | ||
| 225 | + __init__). | ||
| 225 | 226 | """ | |
| 226 | 227 | # clear the old values in _flag_map | |
| 227 | 228 | try: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments