This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·129 lines (100 loc) · 4.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import json
import hashlib
import shutil
import glob
import constants
import datetime
from git import Repo
from packaging import version
####### Functions
def readDatasFromFile(filePath):
return json.loads(open(filePath, 'rb').read())
def writeDatasIntoFile(filePath, datas):
with open(filePath, 'w') as f:
json.dump(datas, f)
def getMd5Checksum(filePath):
return hashlib.md5(open(filePath,'rb').read()).hexdigest()
def cleanAllKeys():
# remove old root keys
fileKeysPath = glob.glob('/tmp/repo/AANM/keys/*')
if len(fileKeysPath) > 1:
oldest_file = min(fileKeysPath, key=os.path.getctime)
os.remove(oldest_file)
# remove old addons keys
allAddonsKeys = {}
fileAddonsKeysPath = glob.glob('/tmp/repo/AANM/addons/*.bisign')
for fileKeyPath in fileAddonsKeysPath:
filename = fileKeyPath.replace('/tmp/repo/AANM/addons/', '')
filenameSplit = filename.split('.')
name = filenameSplit[0]
curVersion = filenameSplit[3] + '.' + filenameSplit[4]
if name in allAddonsKeys :
if version.parse(allAddonsKeys[name]['version']) > version.parse(curVersion) :
os.remove(fileKeyPath)
else:
os.remove(allAddonsKeys[name]['filePath'])
allAddonsKeys[name] = {
'version' : curVersion,
'filePath' : fileKeyPath
}
# remove old optionals addons keys
allOptionalsAddonsPath = glob.glob('/tmp/repo/AANM/optionals/*')
for optionalAddonPath in allOptionalsAddonsPath:
fileList = glob.glob(optionalAddonPath + '/addons/*.bisign')
if len(fileList) > 1:
oldest_file = min(fileList, key=os.path.getctime)
os.remove(oldest_file)
def updatemod(datas, aceZipChecksum):
# git clone
cloned_repo = Repo.clone_from('https:// ' + constants.GITHUB_USERNAME + ':' + constants.GITHUB_TOKEN + '@github.com/Vindicta-Team/Automated-Ace-No-Medical', '/tmp/repo')
if os.path.isdir('/tmp/repo/AANM'):
shutil.rmtree('/tmp/repo/AANM')
shutil.copytree(aceModPath, '/tmp/repo/AANM', False, None, shutil.copy2, False, True)
# remove medical files
medicalFileList = glob.glob('/tmp/repo/AANM/addons/ace_medical*')
for medicalFilePath in medicalFileList:
os.remove(medicalFilePath)
# remove other files requiring medical
fireFileList = glob.glob('/tmp/repo/AANM/addons/ace_fire*')
for fireFilePath in fireFileList:
os.remove(fireFilePath)
fireFileList = glob.glob('/tmp/repo/AANM/addons/ace_killtracker*')
for fireFilePath in fireFileList:
os.remove(fireFilePath)
cleanAllKeys()
# copy mod files
shutil.copyfile('/app/aanm-files/mod.cpp', '/tmp/repo/AANM/mod.cpp')
shutil.copyfile('/app/aanm-files/meta.cpp', '/tmp/repo/AANM/meta.cpp')
# comit files
cloned_repo.git.add('*')
cloned_repo.index.commit("update-" + datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
cloned_repo.remotes.origin.push()
# if update done update
datas['ace'] = aceZipChecksum
writeDatasIntoFile(constants.JSON_FILE_DB, datas)
print('\n\n AANM update done')
####### Init logic
# clean up and update mod
if os.path.isfile('/tmp/ace.zip'):
os.remove('/tmp/ace.zip')
if os.path.isdir('/tmp/repo'):
shutil.rmtree('/tmp/repo')
aceModPath = '/app/mods/steamapps/workshop/content/'+constants.ARMA_APPID+'/'+constants.ACE_APPID
if not os.path.exists(aceModPath):
os.makedirs(aceModPath)
# get last ace version
os.system("cd /home/steam/steamcmd && ./steamcmd.sh +login " + constants.STEAM_USERNAME + " '" + constants.STEAM_PASSWORD + "' +force_install_dir " + constants.INSTALL_DIR + " +workshop_download_item " + constants.ARMA_APPID + " " + constants.ACE_APPID + " validate +quit")
# Zip and checksum it
result = shutil.make_archive('/tmp/ace', 'zip', aceModPath)
aceZipChecksum = getMd5Checksum('/tmp/ace.zip')
if os.path.exists(constants.JSON_FILE_DB):
# retrieve data
datas = readDatasFromFile(constants.JSON_FILE_DB)
# update if needed
if datas['ace'] != aceZipChecksum:
updatemod(datas, aceZipChecksum)
else:
datas = json.loads('{"ace":"123"}')
updatemod(datas, aceZipChecksum)
print('\n\n AANM check finished \n\n')