Example #1
0
def eclean_pkg(destructive=False,
               package_names=False,
               time_limit=0,
               exclude_file='/etc/eclean/packages.exclude'):
    '''
    Clean obsolete binary packages

    destructive
        Only keep minimum for reinstallation

    package_names
        Protect all versions of installed packages. Only meaningful if used
        with destructive=True

    time_limit <time>
        Don't delete distfiles files modified since <time>
        <time> is an amount of time: "1y" is "one year", "2w" is
        "two weeks", etc. Units are: y (years), m (months), w (weeks),
        d (days) and h (hours).

    exclude_file
        Path to exclusion file. Default is /etc/eclean/packages.exclude
        This is the same default eclean-pkg uses. Use None if this file
        exists and you want to ignore.

    Returns a dict containing the cleaned binary packages:

    .. code-block:: python

        {'cleaned': {<dist file>: <size>},
         'total_cleaned': <size>}

    CLI Example:

    .. code-block:: bash

        salt '*' gentoolkit.eclean_pkg destructive=True
    '''
    if exclude_file is None:
        exclude = None
    else:
        try:
            exclude = _parse_exclude(exclude_file)
        except excludemod.ParseExcludeFileException as e:
            ret = {e: 'Invalid exclusion file: {0}'.format(exclude_file)}
            return ret

    if time_limit != 0:
        time_limit = cli.parseTime(time_limit)

    clean_size = 0
    # findPackages requires one arg, but does nothing with it.
    # So we will just pass None in for the required arg
    clean_me = search.findPackages(None,
                                   destructive=destructive,
                                   package_names=package_names,
                                   time_limit=time_limit,
                                   exclude=exclude,
                                   pkgdir=search.pkgdir)

    cleaned = dict()

    def _eclean_progress_controller(size, key, *args):
        cleaned[key] = _pretty_size(size)
        return True

    if clean_me:
        cleaner = clean.CleanUp(_eclean_progress_controller)
        clean_size = cleaner.clean_pkgs(clean_me, search.pkgdir)

    ret = {'cleaned': cleaned, 'total_cleaned': _pretty_size(clean_size)}
    return ret
Example #2
0
def doAction(action,options,exclude={}, output=None):
	"""doAction: execute one action, ie display a few message, call the right
	find* function, and then call doCleanup with its result."""
	# define vocabulary for the output
	if action == 'packages':
		files_type = "binary packages"
	else:
		files_type = "distfiles"
	saved = {}
	deprecated = {}
	# find files to delete, depending on the action
	if not options['quiet']:
		output.einfo("Building file list for "+action+" cleaning...")
	if action == 'packages':
		clean_me = findPackages(
			options,
			exclude=exclude,
			destructive=options['destructive'],
			package_names=options['package-names'],
			time_limit=options['time-limit'],
			pkgdir=pkgdir,
			#port_dbapi=Dbapi(portage.db[portage.root]["porttree"].dbapi),
			#var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi),
		)
	else:
		# accept defaults
		engine = DistfilesSearch(output=options['verbose-output'],
			#portdb=Dbapi(portage.db[portage.root]["porttree"].dbapi),
			#var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi),
		)
		clean_me, saved, deprecated = engine.findDistfiles(
			exclude=exclude,
			destructive=options['destructive'],
			fetch_restricted=options['fetch-restricted'],
			package_names=options['package-names'],
			time_limit=options['time-limit'],
			size_limit=options['size-limit'],
			deprecate = options['deprecated']
		)

	# initialize our cleaner
	cleaner = CleanUp(output.progress_controller)

	# actually clean files if something was found
	if clean_me:
		# verbose pretend message
		if options['pretend'] and not options['quiet']:
			output.einfo("Here are the "+files_type+" that would be deleted:")
		# verbose non-pretend message
		elif not options['quiet']:
			output.einfo("Cleaning " + files_type  +"...")
		# do the cleanup, and get size of deleted files
		if  options['pretend']:
			clean_size = cleaner.pretend_clean(clean_me)
		elif action in ['distfiles']:
			clean_size = cleaner.clean_dist(clean_me)
		elif action in ['packages']:
			clean_size = cleaner.clean_pkgs(clean_me,
				pkgdir)
		# vocabulary for final message
		if options['pretend']:
			verb = "would be"
		else:
			verb = "were"
		# display freed space
		if not options['quiet']:
			output.total('normal', clean_size, len(clean_me), verb, action)
	# nothing was found
	elif not options['quiet']:
		output.einfo("Your "+action+" directory was already clean.")
	if saved and not options['quiet']:
		print()
		print( (pp.emph("   The following ") + yellow("unavailable") +
			pp.emph(" files were saved from cleaning due to exclusion file entries")))
		output.set_colors('deprecated')
		clean_size = cleaner.pretend_clean(saved)
		output.total('deprecated', clean_size, len(saved), verb, action)
	if deprecated and not options['quiet']:
		print()
		print( (pp.emph("   The following ") + yellow("unavailable") +
			pp.emph(" installed packages were found")))
		output.set_colors('deprecated')
		output.list_pkgs(deprecated)
Example #3
0
def eclean_pkg(destructive=False, package_names=False, time_limit=0,
               exclude_file='/etc/eclean/packages.exclude'):
    '''
    Clean obsolete binary packages

    destructive
        Only keep minimum for reinstallation

    package_names
        Protect all versions of installed packages. Only meaningful if used
        with destructive=True

    time_limit <time>
        Don't delete distfiles files modified since <time>
        <time> is an amount of time: "1y" is "one year", "2w" is
        "two weeks", etc. Units are: y (years), m (months), w (weeks),
        d (days) and h (hours).

    exclude_file
        Path to exclusion file. Default is /etc/eclean/packages.exclude
        This is the same default eclean-pkg uses. Use None if this file
        exists and you want to ignore.

    Returns a dict containing the cleaned binary packages:

    .. code-block:: python

        {'cleaned': {<dist file>: <size>},
         'total_cleaned': <size>}

    CLI Example:

    .. code-block:: bash

        salt '*' gentoolkit.eclean_pkg destructive=True
    '''
    if exclude_file is None:
        exclude = None
    else:
        try:
            exclude = _parse_exclude(exclude_file)
        except excludemod.ParseExcludeFileException as e:
            ret = {e: 'Invalid exclusion file: {0}'.format(exclude_file)}
            return ret

    if time_limit != 0:
        time_limit = cli.parseTime(time_limit)

    clean_size = 0
    # findPackages requires one arg, but does nothing with it.
    # So we will just pass None in for the required arg
    clean_me = search.findPackages(None, destructive=destructive,
                                   package_names=package_names,
                                   time_limit=time_limit, exclude=exclude,
                                   pkgdir=search.pkgdir)

    cleaned = dict()

    def _eclean_progress_controller(size, key, *args):
        cleaned[key] = _pretty_size(size)
        return True

    if clean_me:
        cleaner = clean.CleanUp(_eclean_progress_controller)
        clean_size = cleaner.clean_pkgs(clean_me, search.pkgdir)

    ret = {'cleaned': cleaned,
           'total_cleaned': _pretty_size(clean_size)}
    return ret
Example #4
0
def doAction(action,options,exclude={}, output=None):
	"""doAction: execute one action, ie display a few message, call the right
	find* function, and then call doCleanup with its result."""
	# define vocabulary for the output
	if action == 'packages':
		files_type = "binary packages"
	else:
		files_type = "distfiles"
	saved = {}
	deprecated = {}
	# find files to delete, depending on the action
	if not options['quiet']:
		output.einfo("Building file list for "+action+" cleaning...")
	if action == 'packages':
		clean_me = findPackages(
			options,
			exclude=exclude,
			destructive=options['destructive'],
			package_names=options['package-names'],
			time_limit=options['time-limit'],
			pkgdir=pkgdir,
			#port_dbapi=Dbapi(portage.db[portage.root]["porttree"].dbapi),
			#var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi),
		)
	else:
		# accept defaults
		engine = DistfilesSearch(output=options['verbose-output'],
			#portdb=Dbapi(portage.db[portage.root]["porttree"].dbapi),
			#var_dbapi=Dbapi(portage.db[portage.root]["vartree"].dbapi),
		)
		clean_me, saved, deprecated = engine.findDistfiles(
			exclude=exclude,
			destructive=options['destructive'],
			fetch_restricted=options['fetch-restricted'],
			package_names=options['package-names'],
			time_limit=options['time-limit'],
			size_limit=options['size-limit'],
			deprecate = options['deprecated']
		)

	# initialize our cleaner
	cleaner = CleanUp( output.progress_controller)

	# actually clean files if something was found
	if clean_me:
		# verbose pretend message
		if options['pretend'] and not options['quiet']:
			output.einfo("Here are the "+files_type+" that would be deleted:")
		# verbose non-pretend message
		elif not options['quiet']:
			output.einfo("Cleaning " + files_type  +"...")
		# do the cleanup, and get size of deleted files
		if  options['pretend']:
			clean_size = cleaner.pretend_clean(clean_me)
		elif action in ['distfiles']:
			clean_size = cleaner.clean_dist(clean_me)
		elif action in ['packages']:
			clean_size = cleaner.clean_pkgs(clean_me,
				pkgdir)
		# vocabulary for final message
		if options['pretend']:
			verb = "would be"
		else:
			verb = "were"
		# display freed space
		if not options['quiet']:
			output.total('normal', clean_size, len(clean_me), verb, action)
	# nothing was found
	elif not options['quiet']:
		output.einfo("Your "+action+" directory was already clean.")
	if saved and not options['quiet']:
		print()
		print( (pp.emph("   The following ") + yellow("unavailable") +
			pp.emph(" files were saved from cleaning due to exclusion file entries")))
		output.set_colors('deprecated')
		clean_size = cleaner.pretend_clean(saved)
		output.total('deprecated', clean_size, len(saved), verb, action)
	if deprecated and not options['quiet']:
		print()
		print( (pp.emph("   The following ") + yellow("unavailable") +
			pp.emph(" installed packages were found")))
		output.set_colors('deprecated')
		output.list_pkgs(deprecated)