2019-11-25 08:42:18 -06:00
|
|
|
#! /usr/bin/env python
|
|
|
|
""" Upload socializer to the ftp server. """
|
|
|
|
import sys
|
2019-11-25 10:49:58 -06:00
|
|
|
import os
|
|
|
|
import glob
|
2019-11-25 08:42:18 -06:00
|
|
|
import ftplib
|
|
|
|
|
2019-11-25 10:49:58 -06:00
|
|
|
transferred=0
|
|
|
|
|
|
|
|
def convert_bytes(n):
|
|
|
|
K, M, G, T, P = 1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50
|
|
|
|
if n >= P:
|
|
|
|
return '%.2fPb' % (float(n) / T)
|
|
|
|
elif n >= T:
|
|
|
|
return '%.2fTb' % (float(n) / T)
|
|
|
|
elif n >= G:
|
|
|
|
return '%.2fGb' % (float(n) / G)
|
|
|
|
elif n >= M:
|
|
|
|
return '%.2fMb' % (float(n) / M)
|
|
|
|
elif n >= K:
|
|
|
|
return '%.2fKb' % (float(n) / K)
|
|
|
|
else:
|
|
|
|
return '%d' % n
|
|
|
|
|
|
|
|
def callback(progress):
|
|
|
|
global transferred
|
|
|
|
transferred = transferred+len(progress)
|
|
|
|
print("Uploaded {}".format(convert_bytes(transferred),))
|
|
|
|
|
|
|
|
ftp_server = os.environ.get("FTP_SERVER") or sys.argv[1]
|
|
|
|
ftp_username = os.environ.get("FTP_USERNAME") or sys.argv[2]
|
|
|
|
ftp_password = os.environ.get("FTP_PASSWORD") or sys.argv[3]
|
2019-12-10 10:43:55 -06:00
|
|
|
version = os.environ.get("CI_COMMIT_TAG") or "alpha"
|
2019-11-25 10:49:58 -06:00
|
|
|
version = version.replace("v", "")
|
|
|
|
|
|
|
|
print("Uploading files to the Socializer server...")
|
|
|
|
connection = ftplib.FTP(ftp_server)
|
|
|
|
print("Connected to FTP server {}".format(ftp_server,))
|
|
|
|
connection.login(user=ftp_username, passwd=ftp_password)
|
|
|
|
print("Logged in successfully")
|
|
|
|
connection.cwd("static/files/")
|
|
|
|
if version not in connection.nlst():
|
|
|
|
print("Creating version directory {} because does not exists...".format(version,))
|
|
|
|
connection.mkd(version)
|
2019-12-11 11:13:52 -06:00
|
|
|
|
|
|
|
if "update" not in connection.nlst():
|
|
|
|
print("Creating update info directory because does not exists...")
|
|
|
|
connection.mkd("update")
|
2019-11-25 10:49:58 -06:00
|
|
|
connection.cwd(version)
|
|
|
|
print("Moved into version directory")
|
2019-12-11 11:13:52 -06:00
|
|
|
files = glob.glob("*.zip")+glob.glob("*.exe")+glob.glob("*.json")
|
2019-11-25 10:49:58 -06:00
|
|
|
print("These files will be uploaded into the version folder: {}".format(files,))
|
|
|
|
for file in files:
|
|
|
|
transferred = 0
|
|
|
|
print("Uploading {}".format(file,))
|
|
|
|
with open(file, "rb") as f:
|
2019-12-11 11:13:52 -06:00
|
|
|
if file.endswith("json"):
|
|
|
|
connection.storbinary('STOR ../update/%s' % file, f, callback=callback, blocksize=1024*1024)
|
|
|
|
else:
|
|
|
|
connection.storbinary('STOR %s' % file, f, callback=callback, blocksize=1024*1024)
|
2019-11-25 10:49:58 -06:00
|
|
|
print("Upload completed. exiting...")
|
|
|
|
connection.quit()
|