install

installer
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/install

commit 800b1b5574ab0034840e142285d73871bb1b7089
parent 1a5ba871c10c7d19d85d24ea41d5cbd57ad69068
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 29 Nov 2016 18:08:50 +0100

Add(Basic handling for package): Now downloading missing packages

Diffstat:
Rpkgs/test/__init__.py -> pkgs/binutils_p1/__init__.py | 0
Apkgs/binutils_p1/binutils_p1.py | 45+++++++++++++++++++++++++++++++++++++++++++++
Dpkgs/test/test.py | 45---------------------------------------------
Mscreens/install/install.py | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 114 insertions(+), 46 deletions(-)

diff --git a/pkgs/test/__init__.py b/pkgs/binutils_p1/__init__.py diff --git a/pkgs/binutils_p1/binutils_p1.py b/pkgs/binutils_p1/binutils_p1.py @@ -0,0 +1,45 @@ +################################### LICENSE #################################### +# Copyright 2016 Morphux # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +## +# binutils_p1.py +# Created: 29/11/2016 +# By: Louis Solofrizzo <louis@morphux.org> +## + +class Binutils_P1: + + conf_lst = {} + e = False + + def init(self, c_lst, ex): + self.conf_lst = c_lst + self.e = ex + self.config = { + "name": "binutils", # Name of the package + "version": "2.27", # Version of the package + "size": 519, # Size of the installed package (MB) + "archive": "binutils-2.27.tar.bz2", # Archive name + "cheksum": "2869c9bf3e60ee97c74ac2a6bf4e9d68", # Checksum of the archive + "SBU": 1, # SBU (Compilation time) + "tmp_install": True, # Is this package part of the temporary install + "next": "test2", # Next package to install + "urls": [ # Url to download the package. The first one must be morphux servers + "ftp://install.morphux.org/packages/binutils-2.27.tar.bz2", + "http://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.bz2", + ] + } + return self.config diff --git a/pkgs/test/test.py b/pkgs/test/test.py @@ -1,45 +0,0 @@ -################################### LICENSE #################################### -# Copyright 2016 Morphux # -# # -# Licensed under the Apache License, Version 2.0 (the "License"); # -# you may not use this file except in compliance with the License. # -# You may obtain a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -# Unless required by applicable law or agreed to in writing, software # -# distributed under the License is distributed on an "AS IS" BASIS, # -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -# See the License for the specific language governing permissions and # -# limitations under the License. # -################################################################################ - -## -# test.py -# Created: 25/11/2016 -# By: Louis Solofrizzo <louis@morphux.org> -## - -# This a temporary file, here in order to test the install process. - -class Test: - - conf_lst = {} - - def init(self, c_lst): - self.conf_lst = c_lst - self.config = { - "name": "test", # Name of the package - "version": "1.0", # Version of the package - "size": 100, # Size of the installed package - "archive": "test-1.0.tar.gz", # Archive name - "cheksum": "", # Checksum of the archive - "SBU": 1, # SBU (Compilation time) - "tmp_install": False, # Is this package part of the temporary install - "next": "test2", # Next package to install - "urls": [ # Url to download the package. The first one must be morphux servers - "http://url1.com/", - "http://url2.com/", - ] - } - return self.config diff --git a/screens/install/install.py b/screens/install/install.py @@ -23,6 +23,7 @@ import json import os import time +from urllib.request import urlretrieve from subprocess import Popen, PIPE, STDOUT, call class Install: @@ -36,6 +37,7 @@ class Install: modules = {} # Module object pkgs = {} # Packages instances mnt_point = "/mnt/morphux" # Install mount point + arch_dir = "/opt/packages/" ## # Functions @@ -82,6 +84,14 @@ class Install: # Mount the partitions self.mount() + # If the installation require a 2-Phase install + if self.conf_lst["config"]["TMP_INSTALL"]: + # Create the tools directory + self.exec(["mkdir", "-v", self.mnt_point + "/tools"]) + # Link between the host and the install + self.exec(["ln", "-sv", self.mnt_point + "/tools", "/"]) + self.phase_1_install() + # Load all the packages configuration files # path: Default to ./pkgs def load_pkgs(self, path = "pkgs"): @@ -107,7 +117,7 @@ class Install: print("Reading info on "+ name +" ...", end="") klass = klass() # Calling the init function of each package - config = klass.init(self.conf_lst) + config = klass.init(self.conf_lst, self.exec) # Saving the configuration of the object self.pkgs[config["name"]] = [klass, config] print("\tDone !") @@ -236,3 +246,61 @@ class Install: self.exec(["mkdir", "-pv", self.mnt_point + "/tmp"]) self.exec(["mount", "-v", "-t", "ext4", p["part"], self.mnt_point + "/tmp"]) return 0 + + # This function launch the phase-1 full installation + def phase_1_install(self): + pkg_phase_1 = {} # List of package to install for phase 1 + total_size = 0 # Total size of the install + total_sbus = 0 # Total time of the install, in SBUs + + for name, pkg in self.pkgs.items(): + if pkg[1]["tmp_install"]: + total_size += pkg[1]["size"] + total_sbus += pkg[1]["SBU"] + pkg_phase_1[name] = pkg + + self.pkg_download(pkg_phase_1) + + # This function take an object of packages, check if the sources are there. + # If they aren't, the function download them. + def pkg_download(self, pkg_list): + to_dl = [] # Package to download + + # If the archive directory is not here, we create it + if os.path.isdir(self.arch_dir) == False: + self.exec(["mkdir", "-vp", self.arch_dir]) + + for name, pkg in self.pkgs.items(): + # Archive is not here, we need to download it. + if os.path.isfile(self.arch_dir + pkg[1]["archive"]) == False: + to_dl.append(pkg[1]) + + # If we got any package to download, download them. + if len(to_dl): + self.archive_dowload(to_dl) + + # This function handle the downloading of archive + # The lst is a list of package to download + def archive_dowload(self, lst): + dl_len = len(lst) # Number of packages to download + to_dl = 1 # Current archives downloaded + + # First call to the update screen + self.dlg.gauge_start("Downloading "+ str(dl_len) +" packages ...", width=50) + + # Iterate over packages to download + for conf in lst: + dl_ok = 0 + i = 0 + # Test multiples urls in case one fail + # TODO: Handle exception from retrieving + while dl_ok == 0: + # Update the progress bar + self.dlg.gauge_update(int((to_dl * 100) / dl_len), + "Getting "+ conf["archive"]+ "... ("+ str(to_dl) +"/"+ str(dl_len) +")", True) + urlretrieve(conf["urls"][i], self.arch_dir + conf["archive"]) + i += 1 + dl_ok = 1 + to_dl += 1 + + self.dlg.gauge_stop()