Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
f7872ade
Commit
f7872ade
authored
Sep 10, 2018
by
Virgil Grigoras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Own function for getting the current commit hash and datetime
parent
cb5adb3a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
11 deletions
+28
-11
helper.py
cps/helper.py
+17
-0
web.py
cps/web.py
+9
-10
version
version
+2
-1
No files found.
cps/helper.py
View file @
f7872ade
...
@@ -547,6 +547,7 @@ def check_unrar(unrarLocation):
...
@@ -547,6 +547,7 @@ def check_unrar(unrarLocation):
error
=
True
error
=
True
return
(
error
,
version
)
return
(
error
,
version
)
def
is_sha1
(
sha1
):
def
is_sha1
(
sha1
):
if
len
(
sha1
)
!=
40
:
if
len
(
sha1
)
!=
40
:
return
False
return
False
...
@@ -555,3 +556,19 @@ def is_sha1(sha1):
...
@@ -555,3 +556,19 @@ def is_sha1(sha1):
except
ValueError
:
except
ValueError
:
return
False
return
False
return
True
return
True
def
get_current_version_info
():
try
:
with
open
(
'version'
,
'r'
)
as
f
:
content
=
f
.
readlines
()
content
=
[
x
.
strip
()
for
x
in
content
]
if
len
(
content
)
!=
2
:
return
False
if
is_sha1
(
content
[
0
])
and
len
(
content
[
1
])
>
0
:
return
{
'sha'
:
content
[
0
],
'datetime'
:
content
[
1
]}
except
FileNotFoundError
:
return
False
return
False
cps/web.py
View file @
f7872ade
...
@@ -1094,14 +1094,11 @@ def get_update_status():
...
@@ -1094,14 +1094,11 @@ def get_update_status():
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
if
request
.
method
==
"GET"
:
if
request
.
method
==
"GET"
:
# get current commit hash from file
version
=
helper
.
get_current_version_info
()
try
:
if
version
is
False
:
with
open
(
'version'
,
'r'
)
as
f
:
status
[
'current_commit_hash'
]
=
_
(
u'Unknown'
)
data
=
f
.
read
()
.
replace
(
'
\n
'
,
''
)
else
:
if
helper
.
is_sha1
(
data
):
status
[
'current_commit_hash'
]
=
version
[
'sha'
]
status
[
'current_commit_hash'
]
=
data
except
FileNotFoundError
:
pass
try
:
try
:
r
=
requests
.
get
(
repository_url
+
'/git/refs/heads/master'
)
r
=
requests
.
get
(
repository_url
+
'/git/refs/heads/master'
)
...
@@ -2749,10 +2746,12 @@ def profile():
...
@@ -2749,10 +2746,12 @@ def profile():
@
login_required
@
login_required
@
admin_required
@
admin_required
def
admin
():
def
admin
():
commit
=
'$Format:
%
cI$'
version
=
helper
.
get_current_version_info
()
if
commit
.
startswith
(
"$"
)
:
if
version
is
False
:
commit
=
_
(
u'Unknown'
)
commit
=
_
(
u'Unknown'
)
else
:
else
:
commit
=
version
[
'datetime'
]
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
tz
=
datetime
.
timedelta
(
seconds
=
time
.
timezone
if
(
time
.
localtime
()
.
tm_isdst
==
0
)
else
time
.
altzone
)
form_date
=
datetime
.
datetime
.
strptime
(
commit
[:
19
],
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S"
)
form_date
=
datetime
.
datetime
.
strptime
(
commit
[:
19
],
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S"
)
if
len
(
commit
)
>
19
:
# check if string has timezone
if
len
(
commit
)
>
19
:
# check if string has timezone
...
...
version
View file @
f7872ade
$Format:%H$
$Format:%H$
$Format:%cI$
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment