1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-08-13 16:53:54 -04:00

Updated libs to include new pyGitHub modules.

Updated versionChecker code to reflect new pyGitHub module.
This commit is contained in:
echel0n 2014-11-15 23:58:37 -08:00
parent ea2ec2390a
commit 9abe5ea859
3 changed files with 19 additions and 111 deletions

View File

@ -108,6 +108,9 @@ GIT_REMOTE = ''
GIT_REMOTE_URL = ''
CUR_COMMIT_BRANCH = ''
GIT_ORG = 'SiCKRAGETV'
GIT_REPO = 'SickRage'
INIT_LOCK = Lock()
started = False
@ -507,7 +510,7 @@ def initialize(consoleLogging=True):
USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, TMDB_API_KEY, DEBUG, PROXY_SETTING, PROXY_INDEXERS, \
AUTOPOSTPROCESSER_FREQUENCY, DEFAULT_AUTOPOSTPROCESSER_FREQUENCY, MIN_AUTOPOSTPROCESSER_FREQUENCY, \
ANIME_DEFAULT, NAMING_ANIME, ANIMESUPPORT, USE_ANIDB, ANIDB_USERNAME, ANIDB_PASSWORD, ANIDB_USE_MYLIST, \
ANIME_SPLIT_HOME, SCENE_DEFAULT, PLAY_VIDEOS, BACKLOG_DAYS
ANIME_SPLIT_HOME, SCENE_DEFAULT, PLAY_VIDEOS, BACKLOG_DAYS, GIT_ORG, GIT_REPO
if __INITIALIZED__:
return False

View File

@ -1,95 +0,0 @@
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
# This file is part of SickRage.
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
try:
import json
except ImportError:
from lib import simplejson as json
import helpers
class GitHub(object):
"""
Simple api wrapper for the Github API v3. Currently only supports the small thing that SB
needs it for - list of commits.
"""
def __init__(self, github_repo_user, github_repo, branch):
self.github_repo_user = github_repo_user
self.github_repo = github_repo
self.branch = branch
def _access_API(self, path, params=None):
"""
Access the API at the path given and with the optional params given.
path: A list of the path elements to use (eg. ['repos', 'midgetspy', 'Sick-Beard', 'commits'])
params: Optional dict of name/value pairs for extra params to send. (eg. {'per_page': 10})
Returns a deserialized json object of the result. Doesn't do any error checking (hope it works).
"""
url = 'https://api.github.com/' + '/'.join(path)
if params and type(params) is dict:
url += '?' + '&'.join([str(x) + '=' + str(params[x]) for x in params.keys()])
parsedJSON = helpers.getURL(url, json=True)
if not parsedJSON:
return []
return parsedJSON
def commits(self):
"""
Uses the API to get a list of the 100 most recent commits from the specified user/repo/branch, starting from HEAD.
user: The github username of the person whose repo you're querying
repo: The repo name to query
branch: Optional, the branch name to show commits from
Returns a deserialized json object containing the commit info. See http://developer.github.com/v3/repos/commits/
"""
access_API = self._access_API(['repos', self.github_repo_user, self.github_repo, 'commits'],
params={'per_page': 100, 'sha': self.branch})
return access_API
def compare(self, base, head, per_page=1):
"""
Uses the API to get a list of compares between base and head.
user: The github username of the person whose repo you're querying
repo: The repo name to query
base: Start compare from branch
head: Current commit sha or branch name to compare
per_page: number of items per page
Returns a deserialized json object containing the compare info. See http://developer.github.com/v3/repos/commits/
"""
access_API = self._access_API(
['repos', self.github_repo_user, self.github_repo, 'compare', base + '...' + head],
params={'per_page': per_page})
return access_API
def branches(self):
access_API = self._access_API(
['repos', self.github_repo_user, self.github_repo, 'branches'],
params={'per_page': 100})
return access_API

View File

@ -27,8 +27,8 @@ import tarfile
import stat
import traceback
import gh_api as github
import sickbeard
from github import Github
from sickbeard import helpers, notifiers
from sickbeard import ui
from sickbeard import logger
@ -129,11 +129,11 @@ class CheckVersion():
class UpdateManager():
def get_github_repo_user(self):
return 'SiCKRAGETV'
def get_github_org(self):
return sickbeard.GIT_ORG
def get_github_repo(self):
return 'SickRage'
return sickbeard.GIT_REPO
def get_update_url(self):
return sickbeard.WEB_ROOT + "/home/update/?pid=" + str(sickbeard.PID)
@ -141,7 +141,7 @@ class UpdateManager():
class WindowsUpdateManager(UpdateManager):
def __init__(self):
self.github_repo_user = self.get_github_repo_user()
self.github_org = self.get_github_org()
self.github_repo = self.get_github_repo()
self.branch = sickbeard.BRANCH
@ -153,7 +153,7 @@ class WindowsUpdateManager(UpdateManager):
self._newest_version = None
self.gc_url = 'http://code.google.com/p/sickbeard/downloads/list'
self.version_url = 'https://raw.github.com/' + self.github_repo_user + '/' + self.github_repo + '/' + self.branch + '/updates.txt'
self.version_url = 'https://raw.github.com/' + self.github_org + '/' + self.github_repo + '/' + self.branch + '/updates.txt'
def _find_installed_version(self):
version = ''
@ -294,7 +294,7 @@ class WindowsUpdateManager(UpdateManager):
class GitUpdateManager(UpdateManager):
def __init__(self):
self._git_path = self._find_working_git()
self.github_repo_user = self.get_github_repo_user()
self.github_org = self.get_github_org()
self.github_repo = self.get_github_repo()
self.branch = sickbeard.BRANCH
@ -496,7 +496,7 @@ class GitUpdateManager(UpdateManager):
elif self._num_commits_behind > 0:
base_url = 'http://github.com/' + self.github_repo_user + '/' + self.github_repo
base_url = 'http://github.com/' + self.github_org + '/' + self.github_repo
if self._newest_commit_hash:
url = base_url + '/compare/' + self._cur_commit_hash + '...' + self._newest_commit_hash
else:
@ -572,7 +572,7 @@ class GitUpdateManager(UpdateManager):
class SourceUpdateManager(UpdateManager):
def __init__(self):
self.github_repo_user = self.get_github_repo_user()
self.github_org = self.get_github_org()
self.github_repo = self.get_github_repo()
self.branch = sickbeard.BRANCH
@ -617,7 +617,7 @@ class SourceUpdateManager(UpdateManager):
self._num_commits_behind = 0
self._newest_commit_hash = None
gh = github.GitHub(self.github_repo_user, self.github_repo, self.branch)
gh = Github().get_organization(self.github_org).get_repo(self.github_repo)
# try to get newest commit hash and commits behind directly by comparing branch and current commit
if self._cur_commit_hash:
@ -632,7 +632,7 @@ class SourceUpdateManager(UpdateManager):
# fall back and iterate over last 100 (items per page in gh_api) commits
if not self._newest_commit_hash:
for curCommit in gh.commits():
for curCommit in gh.get_commits():
if not self._newest_commit_hash:
self._newest_commit_hash = curCommit['sha']
if not self._cur_commit_hash:
@ -659,7 +659,7 @@ class SourceUpdateManager(UpdateManager):
newest_text += "&mdash; <a href=\"" + self.get_update_url() + "\">Update Now</a>"
elif self._num_commits_behind > 0:
base_url = 'http://github.com/' + self.github_repo_user + '/' + self.github_repo
base_url = 'http://github.com/' + self.github_org + '/' + self.github_repo
if self._newest_commit_hash:
url = base_url + '/compare/' + self._cur_commit_hash + '...' + self._newest_commit_hash
else:
@ -680,7 +680,7 @@ class SourceUpdateManager(UpdateManager):
Downloads the latest source tarball from github and installs it over the existing version.
"""
base_url = 'http://github.com/' + self.github_repo_user + '/' + self.github_repo
base_url = 'http://github.com/' + self.github_org + '/' + self.github_repo
tar_download_url = base_url + '/tarball/' + self.branch
try:
@ -764,5 +764,5 @@ class SourceUpdateManager(UpdateManager):
return True
def list_remote_branches(self):
gh = github.GitHub(self.github_repo_user, self.github_repo, self.branch)
return [x['name'] for x in gh.branches() if x and 'name' in x]
gh = Github().get_organization(self.github_org).get_repo(self.github_repo)
return [x.name for x in gh.get_branches() if x]