Loading bin/isinstall +3 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ InstallSystems Installation Tool import os import argparse import installsystems import installsystems.tools as istools from installsystems.printer import * from installsystems.repository import RepositoryCache from installsystems.image import PackageImage Loading Loading @@ -48,8 +49,8 @@ try: # Partial parse args = p_main.parse_known_args()[0] # looks if arguments is a file or image name if os.path.exists(args.image_name): pkg = PackageImage(args.image_name) if istools.get_path_type(args.image_name) == "file": pkg = PackageImage(istools.complete_path(args.image_name)) else: # init repo cache object repocache = RepositoryCache(args.cache_path, verbose=args.verbose) Loading installsystems/repository.py +8 −34 Original line number Diff line number Diff line Loading @@ -11,39 +11,13 @@ import time import shutil import json import installsystems import installsystems.tools as istools from installsystems.printer import * from installsystems.tarball import Tarball from installsystems.image import Image, PackageImage from installsystems.database import Database class RepositoryBase(object): '''Base repository class''' def complete_path(self, path): '''Format a path to be complete''' if self.path_type(path) in ('http', 'ssh'): return path else: return os.path.abspath(path) def path_type(self, path): '''Return path type''' if path.startswith("http://") or path.startswith("https://"): return "http" # elif path.startswith("ssh://"): # return "ssh" return "file" def cp(self, source, destination): '''Copy a source to destination. Take care of path type''' stype = self.path_type(source) dtype = self.path_type(destination) if stype == dtype == "file": shutil.copy(source, destination) elif stype == "file" and dtype == "": pass class Repository(RepositoryBase): class Repository(object): '''Repository class''' last_name = "last" Loading Loading @@ -136,7 +110,7 @@ class Repository(RepositoryBase): return ts class RepositoryCache(RepositoryBase): class RepositoryCache(object): '''Local repository cache class''' def __init__(self, cache_path, verbose=True): Loading @@ -154,8 +128,8 @@ class RepositoryCache(RepositoryBase): def register(self, name, image, data): '''Register a repository to track''' self.repos[name] = Repository(self.complete_path(image), self.complete_path(data), self.repos[name] = Repository(istools.complete_path(image), istools.complete_pathh(data), verbose=self.verbose) def update(self): Loading @@ -167,9 +141,9 @@ class RepositoryCache(RepositoryBase): self.last(r))) if self.repos[r].last() > self.last(r): # copy last file self.cp(self.repos[r].last_path, os.path.join(self.last_path, r)) istools.cp(self.repos[r].last_path, os.path.join(self.last_path, r)) # copy db file self.cp(self.repos[r].db.path, os.path.join(self.db_path, r)) istools.cp(self.repos[r].db.path, os.path.join(self.db_path, r)) arrow("%s updated" % r, 2, self.verbose) def last(self, reponame): Loading @@ -191,7 +165,7 @@ class RepositoryCache(RepositoryBase): # get remote image remotepath = os.path.join(self.repos[reponame].image_path, filename) arrow("Copying from repository", 2, self.verbose) self.cp(remotepath, localpath) istools.cp(remotepath, localpath) return localpath def find_image(self, name, version): Loading installsystems/tools.py 0 → 100644 +46 −0 Original line number Diff line number Diff line #!/usr/bin/env python # -*- coding: utf-8 -*- # Started 26/05/2011 by Seblu <seblu@seblu.net> ''' InstallSystems Generic Tools Library ''' import os def cp(self, source, destination): '''Copy a source to destination. Take care of path type''' stype = path_type(source) dtype = path_type(destination) if stype == dtype == "file": shutil.copy(source, destination) elif stype == "file" and dtype == "": pass def get_path_type(path): '''Return path type. This is usefull to know what king of path is given''' if path.startswith("http://") or path.startswith("https://"): return "http" elif path.startswith("ssh://"): return "ssh" elif path.startswith("file://") or os.path.exists(path): return "file" return None def complete_path(path): '''Format a path to be complete''' ptype = get_path_type(path) if ptype in ("http", "ssh"): return path elif ptype == "file": if path.startswith("file://"): path = path[len("file://")] return os.path.abspath(path) else: return None def path_strip_file(path): '''Remove file:// header of a local file path''' if path.startswith("file://"): return path[len("file://")] return path Loading
bin/isinstall +3 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ InstallSystems Installation Tool import os import argparse import installsystems import installsystems.tools as istools from installsystems.printer import * from installsystems.repository import RepositoryCache from installsystems.image import PackageImage Loading Loading @@ -48,8 +49,8 @@ try: # Partial parse args = p_main.parse_known_args()[0] # looks if arguments is a file or image name if os.path.exists(args.image_name): pkg = PackageImage(args.image_name) if istools.get_path_type(args.image_name) == "file": pkg = PackageImage(istools.complete_path(args.image_name)) else: # init repo cache object repocache = RepositoryCache(args.cache_path, verbose=args.verbose) Loading
installsystems/repository.py +8 −34 Original line number Diff line number Diff line Loading @@ -11,39 +11,13 @@ import time import shutil import json import installsystems import installsystems.tools as istools from installsystems.printer import * from installsystems.tarball import Tarball from installsystems.image import Image, PackageImage from installsystems.database import Database class RepositoryBase(object): '''Base repository class''' def complete_path(self, path): '''Format a path to be complete''' if self.path_type(path) in ('http', 'ssh'): return path else: return os.path.abspath(path) def path_type(self, path): '''Return path type''' if path.startswith("http://") or path.startswith("https://"): return "http" # elif path.startswith("ssh://"): # return "ssh" return "file" def cp(self, source, destination): '''Copy a source to destination. Take care of path type''' stype = self.path_type(source) dtype = self.path_type(destination) if stype == dtype == "file": shutil.copy(source, destination) elif stype == "file" and dtype == "": pass class Repository(RepositoryBase): class Repository(object): '''Repository class''' last_name = "last" Loading Loading @@ -136,7 +110,7 @@ class Repository(RepositoryBase): return ts class RepositoryCache(RepositoryBase): class RepositoryCache(object): '''Local repository cache class''' def __init__(self, cache_path, verbose=True): Loading @@ -154,8 +128,8 @@ class RepositoryCache(RepositoryBase): def register(self, name, image, data): '''Register a repository to track''' self.repos[name] = Repository(self.complete_path(image), self.complete_path(data), self.repos[name] = Repository(istools.complete_path(image), istools.complete_pathh(data), verbose=self.verbose) def update(self): Loading @@ -167,9 +141,9 @@ class RepositoryCache(RepositoryBase): self.last(r))) if self.repos[r].last() > self.last(r): # copy last file self.cp(self.repos[r].last_path, os.path.join(self.last_path, r)) istools.cp(self.repos[r].last_path, os.path.join(self.last_path, r)) # copy db file self.cp(self.repos[r].db.path, os.path.join(self.db_path, r)) istools.cp(self.repos[r].db.path, os.path.join(self.db_path, r)) arrow("%s updated" % r, 2, self.verbose) def last(self, reponame): Loading @@ -191,7 +165,7 @@ class RepositoryCache(RepositoryBase): # get remote image remotepath = os.path.join(self.repos[reponame].image_path, filename) arrow("Copying from repository", 2, self.verbose) self.cp(remotepath, localpath) istools.cp(remotepath, localpath) return localpath def find_image(self, name, version): Loading
installsystems/tools.py 0 → 100644 +46 −0 Original line number Diff line number Diff line #!/usr/bin/env python # -*- coding: utf-8 -*- # Started 26/05/2011 by Seblu <seblu@seblu.net> ''' InstallSystems Generic Tools Library ''' import os def cp(self, source, destination): '''Copy a source to destination. Take care of path type''' stype = path_type(source) dtype = path_type(destination) if stype == dtype == "file": shutil.copy(source, destination) elif stype == "file" and dtype == "": pass def get_path_type(path): '''Return path type. This is usefull to know what king of path is given''' if path.startswith("http://") or path.startswith("https://"): return "http" elif path.startswith("ssh://"): return "ssh" elif path.startswith("file://") or os.path.exists(path): return "file" return None def complete_path(path): '''Format a path to be complete''' ptype = get_path_type(path) if ptype in ("http", "ssh"): return path elif ptype == "file": if path.startswith("file://"): path = path[len("file://")] return os.path.abspath(path) else: return None def path_strip_file(path): '''Remove file:// header of a local file path''' if path.startswith("file://"): return path[len("file://")] return path