Skip to content

Commit 6e30805

Browse files
author
bspkrs
committed
add support to upload versions json to maven
1 parent b470c39 commit 6e30805

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

Diff for: JsonHelper.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import urllib2, json
1+
import urllib2, json, urllib, os
22

33
def get_remote_json(url):
44
"""Attempts to retrieve a json document from the given URL.
@@ -25,3 +25,18 @@ def get_json_value(json_obj, key):
2525
for subkey in splitted:
2626
value = value[subkey]
2727
return value
28+
29+
30+
def save_remote_json_to_path(url, path):
31+
"""Attempts to retrieve a json document from the given URL and save it to the given path.
32+
33+
:type url: str
34+
:type path: str
35+
:rtype: bool
36+
"""
37+
os.remove(path)
38+
req = urllib2.Request(url, headers={'User-Agent': "Magic Browser"})
39+
r = urllib2.urlopen(req)
40+
with open(path, 'w') as f:
41+
f.write(r.read())
42+
return os.path.exists(path)

Diff for: MCPBot.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, configfile=None, backupcfg=False):
3232
self.test_export_path = self.config.get('EXPORT', 'TEST_EXPORT_PATH', 'testcsv', 'Path under BASE_EXPORT_PATH to write the test CSV files to.')
3333
self.stable_export_path = self.config.get('EXPORT', 'STABLE_EXPORT_PATH', 'stablecsv', 'Path under BASE_EXPORT_PATH to write the stable CSV files to.')
3434
self.test_export_url = self.config.get('EXPORT', 'TEST_EXPORT_URL', 'http://export.mcpbot.bspk.rs')
35-
self.exports_json_url = self.config.get('EXPORT', 'EXPORTS_JSON_URL', 'http://export.mcpbot.bspk.rs/versions.json?limit=1')
35+
self.exports_json_url = self.config.get('EXPORT', 'EXPORTS_JSON_URL', 'http://export.mcpbot.bspk.rs/versions.json')
3636
self.maven_repo_url = self.config.get('EXPORT', 'MAVEN_REPO_URL', 'http://files.minecraftforge.net/maven/manage/upload/de/oceanlabs/mcp/')
3737
self.maven_repo_user = self.config.get('EXPORT', 'MAVEN_REPO_USER', 'mcp')
3838
self.maven_repo_pass = self.config.get('EXPORT', 'MAVEN_REPO_PASS', '')
@@ -63,6 +63,7 @@ def __init__(self, configfile=None, backupcfg=False):
6363
self.registerCommand('latest', self.getLatestMappingVersion, ['any'], 0, 2, '[snapshot|stable] [<mcversion>]', 'Gets a list of the latest mapping versions.', allowpub=True)
6464
self.registerCommand('commit', self.commitMappings, ['mcp_team'], 0, 1, '[<srg_name>|method|field|param]', 'Commits staged mapping changes. If SRG name is specified only that member will be committed. If method/field/param is specified only that member type will be committed. Give no arguments to commit all staged changes.', allowduringreadonly=False)
6565
self.registerCommand('maventime',self.setMavenTime,['mcp_team'], 1, 1, '<HH:MM>', 'Changes the time that the Maven upload will occur using 24 hour clock format.')
66+
6667
self.registerCommand('srg', self.getSrgUrl, ['any'], 1, 1, '<MC Version>', 'Gets the URL of the SRG zip file for the Minecraft version specified.', allowpub=True)
6768

6869
self.registerCommand('gc', self.getClass, ['any'], 1, 2, "<class> [<version>]", "Returns class information. Defaults to current version. Version can be for MCP or MC.", allowpub=True)
@@ -122,7 +123,7 @@ def __init__(self, configfile=None, backupcfg=False):
122123
'ssf': 'sf', 'scm': 'sm', 'ssm': 'sm', 'fscf': 'fsf', 'fssf': 'fsf', 'fscm': 'fsm', 'fssm': 'fsm'}
123124

124125
def clone(self):
125-
return MCPBot(self.configfile, self.nspass, self.backupcfg)
126+
return MCPBot(self.configfile, False)
126127

127128
def onStartUp(self):
128129
super(MCPBot, self).onStartUp()
@@ -289,6 +290,7 @@ def doMavenPush(self, isSnapshot, now):
289290
self.sendPrimChanMessage("%s Pushing %s mappings to Forge Maven." % (typeStr, chanStr))
290291

291292
tries = 0
293+
self.logger.info('Pushing ' + stdZipName)
292294
success = MavenHandler.upload(self.maven_repo_url, self.maven_repo_user, self.maven_repo_pass,
293295
stdZipName, local_path=stdZipDirPath, remote_path=stdZipDir, logger=self.logger)
294296
while tries < self.upload_retry_count and not success:
@@ -313,6 +315,7 @@ def doMavenPush(self, isSnapshot, now):
313315
if success:
314316
self.sendPrimChanOpNotice(success)
315317
tries = 0
318+
self.logger.info('Pushing ' + nodocZipName)
316319
success = MavenHandler.upload(self.maven_repo_url, self.maven_repo_user, self.maven_repo_pass,
317320
nodocZipName, local_path=nodocZipDirPath, remote_path=nodocZipDir, logger=self.logger)
318321
while tries < self.upload_retry_count and not success:
@@ -333,6 +336,28 @@ def doMavenPush(self, isSnapshot, now):
333336
self.sendPrimChanOpNotice(success)
334337
self.sendPrimChanMessage('Semi-live (every %d min), Snapshot (daily ~%s EST), and Stable (committed) MCPBot mapping exports can be found here: %s' % (self.test_export_period, self.maven_upload_time_str, self.test_export_url))
335338

339+
# push json file to maven
340+
if success and JsonHelper.save_remote_json_to_path(self.exports_json_url, os.path.join(self.base_export_path, 'versions.json')):
341+
tries = 0
342+
self.logger.info('Pushing versions.json')
343+
success = MavenHandler.upload(self.maven_repo_url, self.maven_repo_user, self.maven_repo_pass,
344+
'versions.json', local_path=self.base_export_path, remote_path='', logger=self.logger)
345+
while tries < self.upload_retry_count and not success:
346+
tries += 1
347+
self.logger.warning('*** Upload attempt failed. Trying again in 3 minutes. ***')
348+
time.sleep(180)
349+
success = MavenHandler.upload(self.maven_repo_url, self.maven_repo_user, self.maven_repo_pass,
350+
'versions.json', local_path=self.base_export_path, remote_path='', logger=self.logger)
351+
352+
if success and tries == 0:
353+
self.logger.info('Maven upload successful.')
354+
elif success and tries > 0:
355+
self.logger.info('Maven upload successful after %d %s.' % (tries, 'retry' if tries == 1 else 'retries'))
356+
else:
357+
self.logger.error('*** Maven upload failed after %d retries. ***' % tries)
358+
elif success:
359+
self.logger.error('*** Remote JSON was not successfully retrieved. ***')
360+
336361

337362
# def sqlRequest(self, bot, sender, dest, cmd, args):
338363
# sql = ' '.join(args)
@@ -380,7 +405,7 @@ def getLatestMappingVersion(self, bot, sender, dest, cmd, args):
380405
elif args[1].lower() in ['stable', 'snapshot']:
381406
mappingType = args[1].lower()
382407

383-
jsonUrl = self.exports_json_url
408+
jsonUrl = self.exports_json_url + '?limit=1'
384409

385410
# if not version:
386411
# val, status = self.db.getVersions(1)

0 commit comments

Comments
 (0)