Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os, json, urllib, re, sys
- try:
- from config import *
- except:
- print 'Config nicht gefunden bzw. beschaedigt..'
- sys.exit(1)
- try:
- import texttable as tt
- except:
- CSI="\x1B["
- reset=CSI+"m"
- text = 'Das Modul texttables ist nicht installiert:\napt-get install python-pip; pip install texttable'
- print CSI+"31;40m" + text + CSI + "0m"
- sys.exit(1)
- def CheckVersion(steaminf, appid, regex):
- """
- return (needUpdate, version, requiredversion)
- """
- requrl = 'http://api.steampowered.com/ISteamApps/UpToDateCheck/v0001/?appid=%s&version=%s&format=json'
- if not (os.path.isfile(steaminf) and os.access(steaminf,os.R_OK)):
- return (True, '0', 'steam.inf fehlt')
- try:
- steaminf = open(steaminf).read().replace('\r','')
- version = re.findall(regex,steaminf)[0].replace('.','')
- except:
- return (True, '0', 'keine Versionsinfo')
- try:
- response = urllib.urlopen(requrl % (appid, version))
- response = json.load(response)['response']
- except:
- return (True, '0', 'steamapi offline')
- if response.has_key('required_version'):
- return (True, version, response['required_version'])
- else:
- return (False, version, version)
- from os.path import join
- from os import putenv, devnull
- from shlex import split
- class Queue:
- _types = ('hldsupdatetool', 'steamcmd', 'updatetool', 'updatetool_anon')
- _ldpath = { 'hldsupdatetool' : None,
- 'steamcmd' : 'linux32',
- 'updatetool' : '',
- 'updatetool_anon' : ''}
- _bin = { 'hldsupdatetool' : 'steam',
- 'steamcmd' : 'linux32/steamcmd',
- 'updatetool' : 'UpdateTool',
- 'updatetool_anon' : 'UpdateTool'}
- _cmdline = {'hldsupdatetool' : '%(bin)s -command update -game %(appid)s -dir %(dir)s',
- 'steamcmd' : '%(bin)s +login %(login)s %(password)s +force_install_dir %(dir)s +app_update %(appid)s -validate +quit',
- 'updatetool' : '%(bin)s -command update -game %(appid)s -username %(login)s -password %(password)s -dir %(dir)s',
- 'updatetool_anon' : '%(bin)s -command update -game %(appid)s -dir %(dir)s'
- }
- _order = ('updatetool', 'updatetool_anon', 'hldsupdatetool', 'steamcmd')
- def __init__(self):
- self.updates = {}
- for type in self._types:
- self.updates.update({type : []})
- def _create(self, updatertype, updaterpath, serverbase, appid, gamename, login='anonymous', password=''):
- self._binpath = join(updaterpath, self._bin[updatertype])
- self._cmddict = { 'bin' : self._binpath,
- 'appid' : appid,
- 'login' : login,
- 'password' : password,
- 'dir' : serverbase}
- if self._ldpath[updatertype] != None:
- return (split(self._cmdline[updatertype] % self._cmddict),
- ('LD_LIBRARY_PATH', join(updaterpath, self._ldpath[updatertype])),
- gamename, updatertype)
- else:
- return (split(self._cmdline[updatertype] % self._cmddict), None, gamename, updatertype)
- def _createpath(self,master,serverbase):
- if not os.path.exists(os.path.join(master,serverbase)):
- os.mkdir(os.path.join(master,serverbase))
- def add(self, updatertype, updaterpath, serverbase, appid, gamename, login='anonymous', password=''):
- if not updatertype in self._types:
- raise Exception('Unbekannter: %s' % updatertype)
- self._createpath(paths['master'], serverbase)
- self.updates[updatertype].append(self._create(updatertype, updaterpath, serverbase, appid, gamename, login, password))
- def doupdates(self):
- for order in self._order:
- self.updates[order].reverse()
- while len(self.updates[order]) > 0:
- yield self.updates[order].pop()
- update = Queue()
- header = [ 'Spiel', 'AppID',
- 'Aktuell', 'Installierte Version',
- 'Benoetigt','Updater']
- tab = tt.Texttable(max_width=0)
- tab.header(header)
- print 'Beginne Versionscheck...\n'
- for server in servertypes:
- login, password = ('anonymous', '')
- if server.has_key('Login'):
- login, password = server['Login']
- if server['VersionCheckable']:
- steaminf = os.path.join(paths['master'], server['MasterServer'], server['steaminf'])
- appid = server['VersCheckAppID']
- regex = server['VersionCheckRegex']
- needUpdate, version, requiredversion = CheckVersion(steaminf, appid, regex)
- if needUpdate is True:
- #print server['Game'], ' benoetigt ein Update von Version ', version ,' auf Version ', requiredversion
- tab.add_row([server['Game'], server['UpdateAppID'], 'Nein', version, requiredversion, server['Updater']])
- update.add(server['Updater'], paths[server['Updater']], join(paths['master'], server['MasterServer']), server['UpdateAppID'], server['Game'])
- else:
- #print server['Game'], ' ist aktuell. Version: ', version
- tab.add_row([server['Game'], server['UpdateAppID'], 'Ja', version, requiredversion, server['Updater']])
- else:
- tab.add_row([server['Game'], server['UpdateAppID'], 'Unbekannt', 'Unbekannt', 'Unbekannt', server['Updater']])
- update.add(server['Updater'], paths[server['Updater']], join(paths['master'], server['MasterServer']), server['UpdateAppID'], server['Game'], login=login, password=password)
- print tab.draw()
- print '\nBeginne mit dem Updateprozess...\n'
- from subprocess import Popen, PIPE
- for upd, ldpath, gamename, updater in update.doupdates():
- print 'Aktualisiere %s' % gamename,
- if ldpath != None:
- putenv(*ldpath)
- p = Popen(upd, shell=False, stderr=None, stdout=PIPE).communicate()[0]
- #p.wait()
- #print p
- if re.findall(UpdateSuccessRegex[updater],p):
- print '[OK]'
- else:
- print '[Fehler]'
- else:
- p = Popen(upd, shell=False, stderr=None, stdout=PIPE).communicate()[0]
- #p.wait()
- #print p
- if re.findall(UpdateSuccessRegex[updater],p):
- print '[OK]'
- else:
- print '[Fehler]'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement