Skip to content

Commit 648c268

Browse files
committed
CHANGES:
- autoupdate structure changes in DCS, SRS and LotAtc to allow a separate "announce" structure (auto migrated).
1 parent b8df0c1 commit 648c268

File tree

7 files changed

+65
-31
lines changed

7 files changed

+65
-31
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ NODENAME: # this will usually be your hostname
356356
DCS:
357357
installation: '%ProgramFiles%\\Eagle Dynamics\\DCS World Server' # This is your DCS installation. Usually autodetected by the bot.
358358
autoupdate: true # enable auto-update for your DCS servers. Default is false.
359-
# autoupdate: # alternative configuration with a message being posted to Discord after every update
360-
# channel: 11223344556677
361-
# title: DCS has been updated to version {}!
362-
# description: 'The following servers have been updated:'
363-
# footer: Please make sure you update your DCS client to join!
364-
# mention: # Optional mentioning
365-
# - Admin
366-
# - DCS Admin
359+
announce: # Optional: post a message to Discord after every update
360+
channel: 11223344556677
361+
title: DCS has been updated to version {}!
362+
description: 'The following servers have been updated:'
363+
footer: Please make sure you update your DCS client to join!
364+
mention: # Optional mentioning
365+
- Admin
366+
- DCS Admin
367367
use_upnp: true # Do you want to use UPnP to forward your DCS ports automatically? If not set, the global setting will be used.
368368
cloud: true # If you have installed DCS on a NAS or cloud drive, autoupdate and desanitization will only take place once on all your nodes.
369369
desanitize: true # Desanitize your MissionScripting.lua after each update. Default is true.

core/data/impl/nodeimpl.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ async def update_db(self):
433433
await conn.execute(query.rstrip())
434434
cursor = await conn.execute('SELECT version FROM version')
435435
self.db_version = (await cursor.fetchone())[0]
436-
await asyncio.to_thread(migrate, self.node, old_version, self.db_version)
437-
self.log.info(f'- Database upgraded from {old_version} to {self.db_version}.')
436+
rc = await asyncio.to_thread(migrate, self.node, old_version, self.db_version)
437+
if rc != -2:
438+
self.log.info(f'- Database upgraded from {old_version} to {self.db_version}.')
439+
if rc in [-1, -2]:
440+
sys.exit(rc)
438441

439442
def install_plugins(self):
440443
for file in Path('plugins').glob('*.zip'):
@@ -1067,8 +1070,8 @@ async def dcs_update(self, *, branch: Optional[str] = None, version: Optional[st
10671070
"message": f"DCS World updated to version {version} on node {self.node.name}."
10681071
}
10691072
})
1070-
if announce and isinstance(self.locals['DCS'].get('autoupdate'), dict):
1071-
config = self.locals['DCS'].get('autoupdate')
1073+
config = self.config.get('announce')
1074+
if config and announce:
10721075
embed = discord.Embed(
10731076
colour=discord.Colour.blue(),
10741077
title=config.get(

extensions/lotatc/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ MyNode:
1313
LotAtc:
1414
installation: '%ProgramFiles%\LotAtc' # the installation path to your LotAtc installation
1515
autoupdate: true # auto update LotAtc, if a new version is available online (default: false)
16-
# autoupdate: # alternative configuration with a message being posted to Discord after every update
17-
# title: LotAtc has been updated to version {}!
18-
# description: 'The following servers will be updated on the next restart:'
19-
# footer: Please make sure you update your LotAtc client also!
20-
# mention: # Optional mentioning
21-
# - DCS
16+
announce: # Optional: post a message to Discord after every update
17+
title: LotAtc has been updated to version {}!
18+
description: 'The following servers will be updated on the next restart:'
19+
footer: Please make sure you update your LotAtc client also!
20+
mention: # Optional mentioning
21+
- DCS
2222
instances:
2323
DCS.release_server:
2424
# [...]

extensions/lotatc/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ async def schedule(self):
309309
"message": f"{self.name} updated to version {version} on node {self.node.name}."
310310
}
311311
})
312-
if isinstance(self.config.get('autoupdate'), dict):
313-
config = self.config.get('autoupdate')
312+
config = self.config.get('announce')
313+
if config:
314314
servers = []
315315
for instance in self.node.instances:
316316
if (instance.locals.get('extensions', {}).get(self.name) and

extensions/srs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ MyNode:
1717
installation: '%ProgramFiles%\DCS-SimpleRadio-Standalone'
1818
beta: true # allow beta versions
1919
autoupdate: true # auto update your DCS-SRS installation, if a new version is available online (default: false)
20-
# autoupdate: # alternative configuration with a message being posted to Discord after every update
21-
# title: DCS-SRS has been updated to version {}!
22-
# description: 'The following servers have been updated:'
23-
# footer: Please make sure you update your DCS-SRS client also!
24-
# mention: # Optional mentioning
25-
# - DCS
20+
announce: # Optional: post a message to Discord after every update
21+
title: DCS-SRS has been updated to version {}!
22+
description: 'The following servers have been updated:'
23+
footer: Please make sure you update your DCS-SRS client also!
24+
mention: # Optional mentioning
25+
- DCS
2626
# [...]
2727
instances:
2828
DCS.release_server:

extensions/srs/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,8 @@ async def handle_update(self):
534534
"message": f"{self.name} updated to version {version} on node {self.node.name}."
535535
}
536536
})
537-
if isinstance(self.config.get('autoupdate'), dict):
538-
config = self.config.get('autoupdate')
537+
config = self.config.get('announce')
538+
if config:
539539
servers = []
540540
for instance in self.node.instances:
541541
if instance.locals.get('extensions', {}).get(self.name) and instance.locals['extensions'][self.name].get('enabled', True):

migrate.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def migrate(node: Node, old_version: str, new_version: str) -> int:
138138
return migrate_3_12(node)
139139
elif old_version == 'v3.12' and new_version == 'v3.13':
140140
return migrate_3_13(node)
141+
elif old_version == 'v3.14' and new_version == 'v3.15':
142+
return migrate_3_15(node)
141143
return 0
142144

143145
def migrate_3_11(node: Node) -> int:
@@ -162,10 +164,15 @@ def migrate_3_11(node: Node) -> int:
162164

163165

164166
def migrate_3_12(node: Node) -> int:
167+
filename = os.path.join(node.config_dir, 'services', 'scheduler.yaml')
168+
if os.path.exists(filename):
169+
shutil.move(filename, os.path.join(node.config_dir, 'services', 'core.yaml'))
170+
165171
filename = os.path.join(node.config_dir, 'main.yaml')
166172
if not os.path.exists(filename):
167173
node.log.error('main.yaml not found. Exiting.')
168174
return -2
175+
169176
with open(filename, mode='r', encoding='utf-8') as infile:
170177
data = yaml.load(infile)
171178
if 'ovgme' in data.get('opt_plugins', []):
@@ -195,9 +202,6 @@ def migrate_3_12(node: Node) -> int:
195202
yaml.dump(data, outfile)
196203
node.log.info(" => node.yaml auto-migrated, please check")
197204
return -1
198-
filename = os.path.join(node.config_dir, 'services', 'scheduler.yaml')
199-
if os.path.exists(filename):
200-
shutil.move(filename, os.path.join(node.config_dir, 'services', 'core.yaml'))
201205
return 0
202206

203207

@@ -216,6 +220,33 @@ def migrate_3_13(node: Node) -> int:
216220
shutil.move(file, new_file)
217221
return 0
218222

223+
224+
def migrate_3_15(node: Node) -> int:
225+
file = Path(os.path.join(node.config_dir, 'nodes.yaml'))
226+
nodes = yaml.load(file.read_text(encoding='utf-8'))
227+
data = nodes[node.name]
228+
dirty = False
229+
if isinstance(data.get('DCS', {}).get('autoupdate'), dict):
230+
data['DCS']['announce'] = data['DCS'].pop('autoupdate')
231+
data['DCS']['autoupdate'] = True
232+
dirty = True
233+
234+
for name, extension in data['extensions'].items():
235+
if name not in ['SRS', 'LotAtc']:
236+
continue
237+
if isinstance(extension.get('autoupdate'), dict):
238+
extension['announce'] = extension.pop('autoupdate')
239+
extension['autoupdate'] = True
240+
dirty = True
241+
242+
if dirty:
243+
with open(file, mode='w', encoding='utf-8') as outfile:
244+
yaml.dump(nodes, outfile)
245+
node.log.info(" => node.yaml auto-migrated, please check")
246+
return -1
247+
return 0
248+
249+
219250
def migrate_3(node: str):
220251
cfg = ConfigParser()
221252
cfg.read('config/default.ini', encoding='utf-8')

0 commit comments

Comments
 (0)