def mirror_update_scripts(self): '''mirrors the preup.sh and postup.sh scripts''' start = self.version_start end = self.version_end parts = self.parts archs = ('all', ) repos = self._iterate_version_repositories(start, end, parts, archs) # returns generator start_errata = UCS_Version((start.major, start.minor, 1)) # errata updates start with 'errata1' end_errata = UCS_Version( (end.major, end.minor, 999)) # get all available for mirror errata = self._iterate_errata_repositories(start_errata, end_errata, parts, archs) # returns generator components = self.get_components(only_localmirror_enabled=True) comp = self._iterate_component_repositories( components, start, end, archs, for_mirror_list=True) # returns generator all_repos = itertools.chain( repos, errata, comp) # concatenate all generators into a single one for server, struct, phase, path, script in UniventionUpdater.get_sh_files( all_repos, self.script_verify): self.log.info('Mirroring %s:%r/%s to %s', server, struct, phase, path) assert script is not None, 'No script' # use prefix if defined - otherwise file will be stored in wrong directory if server.prefix: filename = os.path.join(self.repository_path, 'mirror', server.prefix, path) else: filename = os.path.join(self.repository_path, 'mirror', path) # Check disabled, otherwise files won't get refetched if they change on upstream server # if os.path.exists(filename): # ud.debug(ud.NETWORK, ud.ALL, "Script already exists, skipping: %s" % filename) # continue makedirs(os.path.dirname(filename)) fd = open(filename, "w") try: fd.write(script) ud.debug(ud.ADMIN, ud.INFO, "Successfully mirrored: %s" % filename) finally: fd.close()
def __init__(self, check_access=True): UniventionUpdater.__init__(self, check_access) self.log = logging.getLogger('updater.Mirror') self.log.addHandler(NullHandler()) self.repository_path = self.configRegistry.get( 'repository/mirror/basepath', '/var/lib/univention-repository') version_end = self.configRegistry.get( 'repository/mirror/version/end') or self.current_version self.version_end = UCS_Version(version_end) version_start = self.configRegistry.get( 'repository/mirror/version/start') or (self.version_major, 0, 0) self.version_start = UCS_Version(version_start) # set architectures to mirror archs = self.configRegistry.get('repository/mirror/architectures', '') if archs: self.architectures = archs.split(' ')
def release_update_available(self, ucs_version=None, errorsto='stderr'): """ Check if an update is available for the `ucs_version`. :param str ucs_version: The UCS release to check. :param str errorsto: Select method of reporting errors; on of 'stderr', 'exception', 'none'. :returns: The next UCS release or None. :rtype: str or None """ if not ucs_version: ucs_version = self.current_version return self.get_next_version(UCS_Version(ucs_version), [], errorsto)
def __init__(self, check_access=True): """ Create new mirror with settings from UCR. :param bool check_access: Check if repository server is reachable on init. :raises ConfigurationError: if configured server is not available immediately. """ UniventionUpdater.__init__(self, check_access) self.log = logging.getLogger('updater.Mirror') self.log.addHandler(NullHandler()) self.repository_path = self.configRegistry.get( 'repository/mirror/basepath', '/var/lib/univention-repository') version_end = self.configRegistry.get( 'repository/mirror/version/end') or self.current_version self.version_end = UCS_Version(version_end) version_start = self.configRegistry.get( 'repository/mirror/version/start') or (self.version_major, 0, 0) self.version_start = UCS_Version(version_start) # set architectures to mirror archs = self.configRegistry.get('repository/mirror/architectures', '') if archs: self.architectures = archs.split(' ')
def list_local_repositories(self, start=None, end=None, maintained=True, unmaintained=False): """ This function returns a sorted list of local (un)maintained repositories. :param start: smallest version that shall be returned. :type start: UCS_Version or None :param end: largest version that shall be returned. :type end: UCS_Version or None :param bool maintained: True if list shall contain maintained repositories. :param bool unmaintained: True if list shall contain unmaintained repositories. :returns: A sorted list of repositories as (directory, UCS_Version, is_maintained) tuples. :rtype: list[tuple(str, UCS_Version, bool)] """ result = [] repobase = os.path.join(self.repository_path, 'mirror') RErepo = re.compile( '^%s/(\d+[.]\d)/(maintained|unmaintained)/(\d+[.]\d+-\d+)$' % (re.escape(repobase), )) for dirname, subdirs, files in os.walk(repobase): match = RErepo.match(dirname) if match: if not maintained and match.group(2) == 'maintained': continue if not unmaintained and match.group(2) == 'unmaintained': continue version = UCS_Version(match.group(3)) if start is not None and version < start: continue if end is not None and end < version: continue result.append( (dirname, version, match.group(2) == 'maintained')) result.sort(key=itemgetter(1)) return result
def release_update_available(self, ucs_version=None, errorsto='stderr'): '''Check if an update is available for the ucs_version''' if not ucs_version: ucs_version = self.current_version return self.get_next_version(UCS_Version(ucs_version), [], errorsto)
def update_dists_files(self): """ Rewrite from | /var/lib/univention-repository/mirror/ | 4.0/ | maintained/ >>> | 4.0-1/ <<< | amd64/ | Packages (relative to <<<) | *.deb to | dists/ | ucs401/ | main/ | binary-amd64/ | Packages (relative to >>>) | Release | debian-installer/ | binary-amd64/ | Packages (relative to >>>) | Release >> from sys import stderr >> logging.basicConfig(stream=stderr, level=logging.DEBUG) >> m = UniventionMirror(False) >> m.update_dists_files() """ # iterate over all local repositories repos = self.list_local_repositories(start=self.version_start, end=self.version_end, unmaintained=False) for outdir, version, is_maintained in repos: self.log.info('Processing %s...', version) start_version = UCS_Version((version.major, 0, 0)) dist = 'univention' if version.major < 4 else 'ucs%(major)d%(minor)d%(patchlevel)d' % version archs = [] for arch in self.architectures: prev = [ (dir2, os.path.join(dir2, arch2, 'Packages')) for (dir2, ver2, maint2) in repos for arch2 in (arch, 'all') if (start_version <= ver2 <= version and os.path.exists( os.path.join(dir2, arch2, 'Packages'))) ] if not prev: self.log.warn('No file "Packages" found for %s', arch) continue prev.reverse() archs.append(arch) main_name = os.path.join(outdir, 'dists', dist, 'main', 'binary-%s' % arch, 'Packages') inst_name = os.path.join(outdir, 'dists', dist, 'main', 'debian-installer', 'binary-%s' % arch, 'Packages') self.log.debug('Generating %s and %s ...', main_name, inst_name) makedirs(os.path.dirname(main_name)) makedirs(os.path.dirname(inst_name)) main = open(main_name + '.tmp', 'w') inst = open(inst_name + '.tmp', 'w') try: for dir2, src_name in prev: self.log.debug('Appending %s ...', src_name) indir = os.path.dirname(dir2) with open(src_name, 'r') as src: for pkg in Packages.iter_paragraphs(src): abs_deb = os.path.join(indir, pkg['Filename']) pkg['Filename'] = os.path.relpath( abs_deb, outdir) dst = inst if pkg[ 'Section'] == 'debian-installer' else main pkg.dump(dst) dst.write('\n') finally: main.close() inst.close() self._compress(main_name) self._compress(inst_name) rel_name = os.path.join(outdir, 'dists', dist, 'main', 'binary-%s' % arch, 'Release') self.log.debug('Generating %s ...', rel_name) with open(rel_name, 'w') as rel: print >> rel, 'Archive: stable' print >> rel, 'Origin: Univention' print >> rel, 'Label: Univention' print >> rel, 'Version: %(major)d.%(minor)d.%(patchlevel)d' % version print >> rel, 'Component: main' print >> rel, 'Architecture: %s' % (arch, ) if archs: self._release(outdir, dist, archs, version)