Skip to content

Commit a5b17d8

Browse files
committed
Move around some url config logic
1 parent da2cad4 commit a5b17d8

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

app/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pbr.version import SemanticVersion
1010

11-
from app.config import GITHUB_REPO
11+
from app.config import github_pypi_package_url
1212
from app.version import __version__, get_latest_version_string_from_github_repo
1313

1414
class SelfUpdatingApp():
@@ -17,7 +17,7 @@ class SelfUpdatingApp():
1717
def __init__(self):
1818
# Fetch most recent version from GitHub repository
1919
self.remote_version = SemanticVersion.from_pip_string(
20-
get_latest_version_string_from_github_repo(GITHUB_REPO))
20+
get_latest_version_string_from_github_repo())
2121
# Fetch locally installed version from PBR
2222
self.local_version = SemanticVersion.from_pip_string(__version__)
2323

@@ -27,7 +27,7 @@ def is_out_of_date(self):
2727

2828
def update(self):
2929
'''Use pip to upgrade the current installation to the newest version.'''
30-
package = 'git+https://github.com/{}.git'.format(GITHUB_REPO)
30+
package = github_pypi_package_url()
3131
command = [sys.executable, '-m', 'pip', 'install', '--upgrade', package]
3232
subprocess.call(command, stdout=sys.stdout, stderr=sys.stderr)
3333

app/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
"""Static application configuration is placed here."""
22

33
GITHUB_REPO = 'BGR360/self-updating-program'
4+
5+
def github_repo_url():
6+
return 'https://github.com/{}'.format(GITHUB_REPO)
7+
8+
def github_pypi_package_url(version=None):
9+
url = 'git+{}.git'.format(github_repo_url())
10+
if version is not None:
11+
url += '@{}'.format(version)
12+
return url
13+
14+
def github_api_url():
15+
return 'https://api.github.com/repos/{}'.format(GITHUB_REPO)

app/version.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
import requests
1010
from pbr.version import VersionInfo
1111

12+
from app.config import github_api_url
13+
1214
INFO = VersionInfo('app').semantic_version()
1315
__version__ = INFO.release_string()
1416
__version_info__ = INFO.version_tuple()
1517

16-
def get_latest_version_string_from_github_repo(repository):
17-
latest_release_url = 'https://api.github.com/repos/{}/releases/latest'.format(repository)
18-
req = requests.get(latest_release_url)
18+
def get_latest_version_string_from_github_repo():
19+
req = requests.get(github_api_url() + '/releases/latest')
1920
api_response = req.json()
2021
version_string = api_response['tag_name']
2122
return version_string

0 commit comments

Comments
 (0)