Skip to content

Commit

Permalink
add builddate
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Jan 11, 2025
1 parent a7fb413 commit e88d3d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def init_app(name, cfgMap, set_env, debug=False):
def BeforeRequest():
session.permanent = True
app.permanent_session_lifetime = datetime.timedelta(days=31)
g.version = appVer
#appVer: KindleEar代码版本,appBuildDate: 更多的反映recipe库的最新版本日期
g.version = f'{appVer}({appBuildDate})'
g.now = lambda: datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)
g.allowSignup = (app.config['ALLOW_SIGNUP'] == 'yes')
g.allowReader = app.config['EBOOK_SAVE_DIR']
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ ENV PYTHONUNBUFFERED=1
USER root
RUN mkdir -p /usr/kindleear /data
WORKDIR /usr/kindleear
COPY --from=builder /usr/kindleear/config.py /usr/kindleear/requirements.txt ./
COPY --from=builder /usr/kindleear/config.py /usr/kindleear/requirements.txt /usr/kindleear/main.py ./
COPY --from=builder /usr/kindleear/tools/mp3cat/mp3cat /usr/local/bin/mp3cat
COPY ./docker/run_docker.sh /usr/local/bin/run_docker.sh
COPY ./docker/gunicorn.conf.py ./main.py ./
COPY ./docker/gunicorn.conf.py ./

#apk add libstdc++ && \
RUN pip install --upgrade pip && \
Expand Down
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Author: cdhigh <https://github.com/cdhigh>

__Version__ = '3.3'
__BuildDate__ = '20250109'

import os, sys, builtins, logging
from application.lib import clogging
Expand All @@ -24,6 +25,7 @@
builtins.__dict__['default_log'] = calibre_log
builtins.__dict__['appDir'] = appDir
builtins.__dict__['appVer'] = __Version__
builtins.__dict__['appBuildDate'] = __BuildDate__
sys.path.insert(0, os.path.join(appDir, 'application', 'lib'))
sys.path.insert(0, appDir)

Expand Down
36 changes: 28 additions & 8 deletions tools/update_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
~=2.31.0 : >=2.31.0,==2.31.*
>=0.2.3,<1.0.0
"""
import re, os, sys, subprocess, secrets
import re, os, sys, subprocess, secrets, datetime
from itertools import chain

def new_secret_key(length=12):
Expand Down Expand Up @@ -142,7 +142,7 @@ def dockerize_config_py(cfgFile, arg):
def gae_location():
try:
output = subprocess.check_output(['gcloud', 'beta', 'app', 'describe'], universal_newlines=True)
lines = output.split('\n')
lines = output.splitlines()
for line in lines:
if 'locationId:' in line:
loc = line[11:].strip()
Expand Down Expand Up @@ -272,22 +272,41 @@ def UpdateOrAddParam(key1, value, key2=None): #Update if exists or add if not
f.write('\n'.join(lines))
print('\n'.join(ret))

#update build date in main.py
def update_build_date(mainFile):
buildDate = datetime.datetime.now().strftime('%Y%m%d')
with open(mainFile, 'r', encoding='utf-8') as f:
lines = f.read().splitlines()
for idx in range(len(lines)):
match = re.match(r'^__BuildDate__\s*=\s*[\'\"]\d{8}[\'\"].*', lines[idx])
if match:
lines[idx] = f"__BuildDate__ = '{buildDate}'"
break
else:
print('Cannot find __BuildDate__ line in main.py. Please verify it.')
return

with open(mainFile, 'w', encoding='utf-8') as f:
f.write('\n'.join(lines) + '\n')

if __name__ == '__main__':
thisDir = os.path.abspath(os.path.dirname(__file__))
cfgFile = os.path.normpath(os.path.join(thisDir, '..', 'config.py'))
reqFile = os.path.normpath(os.path.join(thisDir, '..', 'requirements.txt'))
workerYamlFile = os.path.normpath(os.path.join(thisDir, '..', 'worker.yaml'))
mainFile = os.path.normpath(os.path.join(thisDir, '..', 'main.py'))
if not os.path.exists(cfgFile):
cfgFile = os.path.normpath(os.path.join(thisDir, 'config.py'))
reqFile = os.path.normpath(os.path.join(thisDir, 'requirements.txt'))
workerYamlFile = os.path.normpath(os.path.join(thisDir, 'worker.yaml'))
mainFile = os.path.normpath(os.path.join(thisDir, 'main.py'))

dockerArgs = ''
gaeify = False
arg1 = sys.argv[1] if len(sys.argv) >= 2 else ''
arg2 = sys.argv[2] if len(sys.argv) >= 3 else '' #TARGETPLATFORM
if arg1 == '--help':
print('This script can help you to update config.py and requirements.txt.')
print('This script will update config.py, requirements.txt and main.py.')
print('Command arguments:')
print(' docker : prepare for docker image')
print(' docker[all] : prepare for docker image, install all libs')
Expand All @@ -297,16 +316,16 @@ def UpdateOrAddParam(key1, value, key2=None): #Update if exists or add if not
print(' empty : do not modify config.py, only update requirements.txt')
sys.exit(1)
elif arg1.startswith('docker'):
print('\nUpdating config.py and requirements.txt for Docker deployment.\n')
print('\nUpdating config.py, requirements.txt and main.py for Docker deployment.\n')
dockerize_config_py(cfgFile, arg1)
dockerArgs = arg1
elif arg1.startswith('gae'):
print('\nUpdating config.py and requirements.txt for GAE deployment.\n')
print('\nUpdating config.py, requirements.txt and main.py for GAE deployment.\n')
gaeify_config_py(cfgFile)
update_worker_yaml(workerYamlFile, arg1)
gaeify = True
else:
print('\nThis script can help you to update requirements.txt.\n')
elif arg1 != '-y':
print('\nThis script will update requirements.txt and main.py.\n')
usrInput = input('Press y to continue :')
if usrInput.lower() != 'y':
sys.exit(1)
Expand Down Expand Up @@ -334,5 +353,6 @@ def UpdateOrAddParam(key1, value, key2=None): #Update if exists or add if not
extras.update(dockerArgs.split('[')[-1].rstrip(']').split(','))

write_req(reqFile, db, task, plat, *extras)
print(f'Finished create {reqFile}')
update_build_date(mainFile)
print(f'Finished update {os.path.basename(reqFile)} and {os.path.basename(mainFile)}')
sys.exit(0)

0 comments on commit e88d3d4

Please sign in to comment.