From e18d6a0b9d9cb0c196a6f42fc4eec1de664e8367 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Mon, 15 Dec 2014 20:19:52 +0530 Subject: [PATCH] add apt-repo library --- ee/core/apt-repo.py | 29 ----------------------------- ee/core/apt_repo.py | 43 +++++++++++++++++++++++++++++++++++++++++++ ee/core/variables.py | 5 +++++ 3 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 ee/core/apt-repo.py create mode 100644 ee/core/apt_repo.py diff --git a/ee/core/apt-repo.py b/ee/core/apt-repo.py deleted file mode 100644 index eae22a2d..00000000 --- a/ee/core/apt-repo.py +++ /dev/null @@ -1,29 +0,0 @@ - -from ee.core.variables import EEVariables - - -class EERepo(): - """Manage Repositories""" - - def __init__(self): - """Initialize """ - pass - - def add(self, repo_url=None, codename=None, repo_type=None, ppa=None): - # TODO add repository code - repo_file_path = ("/etc/apt/sources.list.d/" - + EEVariables().ee_repo_file) - try: - with open(repo_file_path, "a") as repofile: - repofile.write("\n" + repo_url + " " + codename + - " " + repo_type) - repofile.close() - except Exception as e: - raise - - def remove(self, repo_url=None, codename=None, repo_type=None, ppa=None): - # TODO remove repository - pass - -# if __name__ == '__main__': -# EERepo().add(repo_url="http://ds.asf", codename="trusty", repo_type="main") diff --git a/ee/core/apt_repo.py b/ee/core/apt_repo.py new file mode 100644 index 00000000..55fc0a11 --- /dev/null +++ b/ee/core/apt_repo.py @@ -0,0 +1,43 @@ + +import os.path +from ee.core.shellexec import EEShellExec +from ee.core.variables import EEVariables + + +class EERepo(): + """Manage Repositories""" + + def __init__(self): + """Initialize """ + pass + + def add(self, repo_url=None, ppa=None): + # TODO add repository code + + if repo_url is not None: + repo_file_path = ("/etc/apt/sources.list.d/" + + EEVariables().ee_repo_file) + try: + with open(repo_file_path, "a") as repofile: + repofile.write(repo_url) + repofile.close() + return True + except IOError as e: + print("File I/O error({0}): {1}".format(e.errno, e.strerror)) + except Exception as e: + print("{error}".format(error=e)) + return False + if ppa is not None: + if EEVariables.ee_platform_distro is not 'Ubuntu': + EEShellExec.cmd_exec("add-apt-repository -y {ppa_name}" + .format(ppa_name=ppa)) + else: + print("Cannot add repo for {distro}" + .format(distro=EEVariables.ee_platform_distro)) + + def remove(self, repo_url=None, codename=None, repo_type=None, ppa=None): + # TODO remove repository + pass + +# if __name__ == '__main__': +# EERepo().add(repo_url="http://ds.asf", codename="trusty", repo_type="main") diff --git a/ee/core/variables.py b/ee/core/variables.py index 6fb3160f..e202645a 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -1,4 +1,5 @@ """EasyEngine core variable module""" +import platform class EEVariables(): @@ -24,6 +25,10 @@ class EEVariables(): ee_postfix_repo = "" ee_postfix = ["postfix"] + ee_platform_distro = platform.linux_distribution()[0] + ee_platform_version = platform.linux_distribution()[1] + ee_platform_codename = platform.linux_distribution()[2] + # Repo ee_repo_file = "ee-repo.list"