Skip to content

Commit

Permalink
Fixed issue 134
Browse files Browse the repository at this point in the history
  • Loading branch information
ukdtom committed Jul 2, 2016
1 parent c6d1712 commit e12ed1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
51 changes: 39 additions & 12 deletions Contents/Code/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ def removeEmptyFolders(path, removeRoot=True):
Log.Exception('The error was: ' + str(e))
return

''' Returns commit time and Id for a git branch '''
def getAtom_UpdateTime_Id(self, url, branch):
# Build AtomUrl
atomUrl = url + '/commits/' + branch + '.atom'
# Get Atom
atom = HTML.ElementFromURL(atomUrl)
mostRecent = atom.xpath('//entry')[0].xpath('./updated')[0].text[:-6]
commitId = atom.xpath('//entry')[0].xpath('./id')[0].text.split('/')[-1][:10]
return {'commitId' : commitId, 'mostRecent' : mostRecent}

''' This function will return a list of bundles, where there is an update avail '''
def getUpdateList(self, req):
Log.Debug('Got a call for getUpdateList')
Expand All @@ -210,13 +220,29 @@ def getUpdateList(self, req):
# Now walk them one by one
for bundle in bundles:
if bundle.startswith('https://github'):
gitTime = datetime.datetime.strptime(self.getLastUpdateTime(req, UAS=True, url=bundle), '%Y-%m-%d %H:%M:%S')
sBundleTime = Dict['installed'][bundle]['date']
bundleTime = datetime.datetime.strptime(sBundleTime, '%Y-%m-%d %H:%M:%S')
if bundleTime < gitTime:
gitInfo = Dict['installed'][bundle]
gitInfo['gitHubTime'] = str(gitTime)
result[bundle] = gitInfo
# Going the new detection way with the commitId?
if 'CommitId' in Dict['installed'][bundle]:
updateInfo = self.getAtom_UpdateTime_Id(bundle, Dict['installed'][bundle]['branch'])
if Dict['installed'][bundle]['CommitId'] != updateInfo['commitId']:
gitInfo = Dict['installed'][bundle]
gitInfo['gitHubTime'] = updateInfo['mostRecent']
result[bundle] = gitInfo
else:
# Sadly has to use timestamps
Log.Info('Using timestamps to detect avail update for ' + bundle)
gitTime = datetime.datetime.strptime(self.getLastUpdateTime(req, UAS=True, url=bundle), '%Y-%m-%d %H:%M:%S')
sBundleTime = Dict['installed'][bundle]['date']
bundleTime = datetime.datetime.strptime(sBundleTime, '%Y-%m-%d %H:%M:%S')
if bundleTime < gitTime:
gitInfo = Dict['installed'][bundle]
gitInfo['gitHubTime'] = str(gitTime)
result[bundle] = gitInfo
else:
# Let's get a CommitId stamped for future times
updateInfo = self.getAtom_UpdateTime_Id(bundle, Dict['installed'][bundle]['branch'])
Log.Info('Stamping %s with a commitId of %s for future ref' %(bundle, updateInfo['commitId']))
Dict['installed'][bundle]['CommitId'] = updateInfo['commitId']
Dict.Save()
Log.Debug('Updates avail: ' + str(result))
req.clear()
req.set_status(200)
Expand Down Expand Up @@ -296,11 +322,6 @@ def getIdentifier(pluginDir):
uasListjson = getUASCacheList()
bFound = False
for git in uasListjson:
'''
if target == 'com.plexapp.plugins.Plex2csv':
print 'GED KIG HER'
continue
'''
if target == uasListjson[git]['identifier']:
Log.Debug('Found %s is part of uas' %(target))
targetGit = {}
Expand Down Expand Up @@ -544,8 +565,11 @@ def saveInstallInfo(url, bundleName, branch):
# Walk the one by one, so we can handle upper/lower case
for git in gits:
if url.upper() == git['repo'].upper():
# Get the last Commit Id of the branch
Id = HTML.ElementFromURL(url + '/commits/' + branch + '.atom').xpath('//entry')[0].xpath('./id')[0].text.split('/')[-1][:10]
key = git['repo']
del git['repo']
git['CommitId'] = Id
git['branch'] = branch
git['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Dict['installed'][key] = git
Expand All @@ -557,9 +581,12 @@ def saveInstallInfo(url, bundleName, branch):
break
if bNotInUAS:
key = url
# Get the last Commit Id of the branch
Id = HTML.ElementFromURL(url + '/commits/master.atom').xpath('//entry')[0].xpath('./id')[0].text.split('/')[-1][:10]
pFile = Core.storage.join_path(self.PLUGIN_DIR, bundleName, 'Contents', 'Info.plist')
pl = plistlib.readPlist(pFile)
git = {}
git['CommitId'] = Id
git['title'] = os.path.basename(bundleName)[:-7]
git['description'] = ''
git['branch'] = branch
Expand Down
1 change: 1 addition & 0 deletions http/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ V2.3 DEV:
#176 UAS: Critical error in updateInstallDict
#178 WT: Fixed issue with intruder detection
#184 WT: Logging can fail on Mac OS
#134 UAS: Wrong time for Latest Update on Github

New:
#170 WT: Added a user guide from Trumpy81. URL is /manual/WebTools-User-Manual.pdf
Expand Down

0 comments on commit e12ed1d

Please sign in to comment.