Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
make backward compatible with 3 < Python < 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
esoadamo committed Feb 11, 2019
1 parent b63c3fc commit fd072b5
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 412 deletions.
19 changes: 9 additions & 10 deletions github_updater.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import os
import requests
import shutil
import tempfile
import zipfile

import requests


class GithubUpdater:
"""
Interface for obtaining latest source codes from GitHub repository
"""

def __init__(self, repo_owner: str, repo_name: str):
def __init__(self, repo_owner, repo_name): # type: (str, str) -> None
"""
Initializes the GitHub updater
:param repo_owner: owner of the GitHub repository to update from
Expand All @@ -20,21 +19,21 @@ def __init__(self, repo_owner: str, repo_name: str):
self.url_release = "https://api.github.com/repos/%s/%s/releases/latest" % (repo_owner, repo_name)
self.url_master_zip = "https://github.com/%s/%s/archive/master.zip" % (repo_owner, repo_name)

def get_latest_release_data(self) -> dict:
def get_latest_release_data(self): # type: () -> dict
"""
Uses GitHub API to obtain all data about latest release and return them as a dict
:return: all data about latest release and as a dict
"""
return requests.get(self.url_release).json()

def get_latest_release_tag(self) -> str:
def get_latest_release_tag(self): # type: () -> str
"""
Fetches the tag of the latest release
:return: the tag of the latest release from GitHub repository
"""
return self.get_latest_release_data()['tag_name']

def get_latest_release_zip(self, target_file: str) -> None:
def get_latest_release_zip(self, target_file): # type: (str) -> None
"""
Downloads the zip with a source code of the latest release from GitHub
:param target_file: where to download the zip file to
Expand All @@ -46,7 +45,7 @@ def get_latest_release_zip(self, target_file: str) -> None:
if chunk:
f.write(chunk)

def get_master(self, target_file: str) -> None:
def get_master(self, target_file): # type: (str) -> None
"""
Downloads the current master branch as a zip file
:param target_file: where to download the master branch zip file to
Expand All @@ -58,7 +57,7 @@ def get_master(self, target_file: str) -> None:
if chunk:
f.write(chunk)

def get_and_extract_newest_release_to_directory(self, target_directory: str) -> None:
def get_and_extract_newest_release_to_directory(self, target_directory): # type: (str) -> None
"""
Downloads and extracts newest release to specified directory
:param target_directory: here will be the code of the newest release placed
Expand All @@ -68,7 +67,7 @@ def get_and_extract_newest_release_to_directory(self, target_directory: str) ->
self.get_latest_release_zip(zip_file)
self._extract_zip(zip_file, target_directory)

def extract_master(self, target_directory: str) -> None:
def extract_master(self, target_directory): # type: (str) -> None
"""
Downloads and extracts code from master branch to specified directory
:param target_directory: here will be the code from master branch placed
Expand All @@ -79,7 +78,7 @@ def extract_master(self, target_directory: str) -> None:
self._extract_zip(zip_file, target_directory)

@staticmethod
def _extract_zip(zip_path: str, target_directory: str) -> None:
def _extract_zip(zip_path, target_directory): # type: (str, str) -> None
"""
Extract zip with source code to target directory and deletes the zip file
:param zip_path: zip file to be extracted
Expand Down
Loading

0 comments on commit fd072b5

Please sign in to comment.