works
Some checks reported errors
continuous-integration/drone/tag Build was killed

This commit is contained in:
shim_
2018-09-09 22:33:45 +02:00
parent 58a2231e35
commit 5cd6d42f17
4 changed files with 218 additions and 107 deletions

View File

@@ -1,6 +1,6 @@
#! /usr/bin/env python
import requests, platform, re, collections, tempfile, os, sys, shutil
import requests, platform, re, collections, tempfile, os, sys, shutil, math
from subprocess import call
version_re = "seafile-server-?_?([\d\.]*)"
@@ -19,6 +19,16 @@ def available(page):
available[m.group(2)] = m.group(0) #{version: link}
return collections.OrderedDict(sorted(available.items(), reverse=True))
def version_int(version):
parts=version.split('.')
rank=len(parts)
from math import pow
no=0
for p in parts:
rank=rank-1
no=no+int(p)*pow(10,rank)
return no
def list_command(page="https://www.seafile.com/en/download/"):
for (version, link) in available(page).items():
print("- %s: %s" % (version, link))
@@ -30,7 +40,7 @@ def current_version_command():
def current_version():
current = os.path.realpath(os.path.join(seaf_home, "seafile-server-latest"))
res = re.findall(version_re,current)
res[0] = "0" + res[0]
if len(res[0]) == 0: return '0'
return '.'.join(res)
def perform_upgrade_command(version,mysql=False,yes=True):
@@ -39,6 +49,7 @@ def perform_upgrade_command(version,mysql=False,yes=True):
target = map(lambda x: int(x), version.split("."))
print len(current) == 1 and current[0] == 0
if len(current) == 1 and current[0] == 0: #Not installed
print("Running installer, please don't change any default values regarding ports.")
installer = os.path.join(seaf_home,"seafile-server-%s" % version,"setup-seafile%s.sh" % ("-mysql" if mysql else ""))
call(["sh","-c",installer],stdout=sys.stdout, stdin=sys.stdin)
return 0
@@ -71,7 +82,7 @@ def install_command(url):
if len(current) == 1: current = current[0]
else: current = "0.0.0"
print("Upgrading from: %s -> %s" % (current, target_version))
perform_upgrade_command(target_version)
perform_upgrade_command(target_version,mysql=(os.environ["SEAF_MYSQL"] or False))
if len(os.listdir(tmp)) != 0:
print("Failed to unpack update")
os.rmdir(tmp)
@@ -79,14 +90,18 @@ def install_command(url):
os.rmdir(tmp)
return 0
#TODO: figure out how to rename main to ""
def main_command(version="latest",page="https://www.seafile.com/en/download/"):
avail = available(page)
install = None
if version == "latest":
install = avail.items()[0]
(install,version) = avail.items()
else:
if version in dict(avail.items()):
install = dict(avail.items())[version]
if version_int(current_version()) == version_int(version):
print("%s(%s) is already installed" % (version,version_int(version)))
return 1
if install:
print("Installing: %s" % install[1])
return install_command(install[1])