Skip to content

Commit

Permalink
improve update
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Jul 6, 2021
1 parent 38beefb commit 9cc9392
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions spug_api/apps/account/management/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ class Command(BaseCommand):
help = '升级Spug版本'

def handle(self, *args, **options):
res = requests.get('https://gitee.com/api/v5/repos/openspug/spug/releases/latest').json()
version, is_repair = res.get('tag_name'), False
if not version:
return self.stderr.write(self.style.ERROR('获取新版本失败,排除网络问题后请附带输出内容至官方论坛反馈'))
if version == settings.SPUG_VERSION:
version, is_repair = settings.SPUG_VERSION, False
res = requests.get(f'https://api.spug.cc/apis/release/latest/?version={version}').json()
if res['error']:
return self.stderr.write(self.style.ERROR(f'获取新版本失败{res["error"]}'))
if not res['data']['has_new']:
self.stdout.write(self.style.SUCCESS(''))
is_repair = True
answer = input(f'当前已是最新版本,是否要进行修复性更新[y|n]?')
else:
self.stdout.write(f'{version} 更新日志:\r\n' + res.get('body', ''))
version = res['data']['version']
self.stdout.write(res['data']['content'])
answer = input(f'发现新版本 {version} 是否更新[y|n]?')
if answer.lower() != 'y':
return

# update web
web_dir = os.path.join(settings.BASE_DIR, '../spug_web')
commands = [
f'curl -o /tmp/spug_web.tar.gz https://cdn.spug.cc/spug/web_{version}.tar.gz',
f'curl -o /tmp/spug_web.tar.gz http://cdn.spug.cc/spug/web_{version}.tar.gz',
f'rm -rf {web_dir}/build',
f'tar xf /tmp/spug_web.tar.gz -C {web_dir}'
]
Expand Down

0 comments on commit 9cc9392

Please sign in to comment.