FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cecli/cecli/versioncheck.py at main · cecli-dev/cecli · GitHub
cecli-dev
cecli
Repository navigation
Code
Issues
11
(11)
Pull requests
8
(8)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cecli
/
cecli
/
versioncheck.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (82 loc) · 2.96 KB
Breadcrumbs
cecli
/
cecli
/
versioncheck.py
Copy path
File metadata and controls
92 lines (82 loc) · 2.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
os
import
sys
import
time
from
pathlib
import
Path
import
packaging
.
version
import
cecli
from
cecli
import
utils
from
cecli
.
dump
import
dump
# noqa
from
cecli
.
helpers
.
file_searcher
import
handle_core_files
VERSION_CHECK_FNAME
=
handle_core_files
(
Path
.
home
()
/
".cecli"
/
"caches"
/
"versioncheck"
)
async
def
install_from_main_branch
(
io
):
"""
Install the latest version of cecli from the main branch of the GitHub repository.
"""
return
await
utils
.
check_pip_install_extra
(
io
,
None
,
"Install the development version of cecli from the main branch?"
,
[
"git+https://github.com/cecli-dev/cecli.git"
],
self_update
=
True
,
)
async
def
install_upgrade
(
io
,
latest_version
=
None
):
"""
Install the latest version of cecli from PyPI.
"""
if
latest_version
:
new_ver_text
=
f"Newer cecli version v
{
latest_version
}
is available."
else
:
new_ver_text
=
"Install latest version of cecli?"
docker_image
=
os
.
environ
.
get
(
"CECLI_DOCKER_IMAGE"
)
if
docker_image
:
text
=
f"
\n
{
new_ver_text
}
To upgrade, run:
\n
\n
docker pull
{
docker_image
}
\n
"
io
.
tool_warning
(
text
)
return
True
success
=
await
utils
.
check_pip_install_extra
(
io
,
None
,
new_ver_text
,
cmd
=
utils
.
get_self_upgrade_command
(),
self_update
=
True
)
if
success
:
io
.
tool_output
(
"Re-run cecli to use new version."
)
sys
.
exit
()
return
async
def
check_version
(
io
,
just_check
=
False
,
verbose
=
False
,
upgrade
=
False
):
if
not
just_check
and
not
upgrade
and
VERSION_CHECK_FNAME
.
exists
():
day
=
60
*
60
*
24
since
=
time
.
time
()
-
os
.
path
.
getmtime
(
VERSION_CHECK_FNAME
)
if
0
<
since
<
day
:
if
verbose
:
hours
=
since
/
60
/
60
io
.
tool_output
(
f"Too soon to check version:
{
hours
:.1f
}
hours"
)
return
import
requests
try
:
response
=
requests
.
get
(
"https://pypi.org/pypi/cecli-dev/json"
)
data
=
response
.
json
()
latest_version
=
data
[
"info"
][
"version"
]
current_version
=
cecli
.
__version__
if
just_check
or
verbose
:
io
.
tool_output
(
f"Current version:
{
current_version
}
"
)
is_update_available
=
packaging
.
version
.
parse
(
latest_version
)
>
packaging
.
version
.
parse
(
current_version
)
except
Exception
as
err
:
io
.
tool_error
(
f"Error checking pypi for new version:
{
err
}
"
)
return
False
finally
:
VERSION_CHECK_FNAME
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
VERSION_CHECK_FNAME
.
touch
()
if
just_check
or
verbose
:
if
is_update_available
:
io
.
tool_output
(
"Update available"
)
else
:
io
.
tool_output
(
"No update available"
)
if
just_check
:
return
is_update_available
if
not
is_update_available
:
return
False
if
await
io
.
confirm_ask
(
"Install updated version?"
,
explicit_yes_required
=
True
,
):
await
install_upgrade
(
io
,
latest_version
)
return
True
Back
|
FazBrowse Home
|
New Git URL