Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 276856 Details for
Bug 371326
app-portage/gentoolkit: eclean-dist enhancement suggestions based on the script "distclean.py" that does [more or less] the same
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
v0.3 of distclean
distclean.py (text/x-python), 6.37 KB, created by
K. Posern
on 2011-06-12 22:40:59 UTC
(
hide
)
Description:
v0.3 of distclean
Filename:
MIME Type:
Creator:
K. Posern
Created:
2011-06-12 22:40:59 UTC
Size:
6.37 KB
patch
obsolete
>#!/usr/bin/env python >## distclean.py version 0.3 (12 Jun 2011) >## >## Removes source files for Gentoo >## packages that are no longer installed >## Use with '-p' (pretend) flag to just get a list of files >## that would be removed >## >## 0.1: Aug 20, 2003 - first version with version number >## 0.2: Jan 11, 2005 - fixes by Emil Beinroth >## 0.3: Jun 12, 2011 - By K. Posern: >## > removed keywords, >## > prepared for python3 >## > added output options, help, usage() >## > made [MODE] parameter mandatory to avoid oopsis >## > adapted to new portage [v2.2] >## >## Copyright (c) 2003, Fredrik Arnerup (e97_far@e.kth.se) >## Copyright (c) 2011, K. Posern (quickhelp@gmail.com) >## All rights reserved. >## >## Redistribution and use in source and binary forms, with or without >## modification, are permitted provided that the following conditions are met: >## >## * Redistributions of source code must retain the above copyright notice, >## this list of conditions and the following disclaimer. >## >## * Redistributions in binary form must reproduce the above copyright >## notice, this list of conditions and the following disclaimer in the >## documentation and/or other materials provided with the distribution. >## >## THIS SOFTWARE IS PROVIDED BY FREDRIK ARNERUP "AS IS" AND ANY >## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED >## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE >## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR >## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER >## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH >## DAMAGE. > >import sys, os, os.path, portage > >DBG=False >VRB=False >QUIET=False >MODE = None >DISTDIR = None > >def usage(msg=None): > global DISTDIR > if msg: print(msg+'\n') > print("""usage: %s [-p|--pretend] [-g|--go] > >Removes source files for Gentoo packages that are no longer installed. >The script will work on the DISTDIR = "%s" > >You need to specify the MODE as one of: > -p / --pretend to just get a list of files that would be removed. > -g' / --go to really *remove* files from the DISTDIR! > >To control the [debug] output of this script: > -q / --quiet nothing except errors will be printed (this overrules -v, -d) > -v / --verbose extra information - e.g. MODE, which files were ignored > -d / --debug debug output > >To display this information: > -h / --help > >By default this script prints: > DISTDIR > WARNINGs [e.g. if a file could not be deleted] > one line for each file that would/was deleted >""" % (sys.argv[0], DISTDIR) ) > sys.exit(0) > >#### COMMANDLINE PARSING #### > >try: DISTDIR = portage.settings['DISTDIR'] >except: sys.exit('Failed to determine the DISTDIR.') > >if len(sys.argv) <= 1: usage() > >for i,arg in enumerate(sys.argv): > if i == 0: continue > # MODE: > if arg == '-p' or arg == '--pretend': > if MODE: usage('You can only specify -p or -g.') > MODE = 'p' > elif arg == '-g' or arg == '--go': > if MODE: usage('You can only specify -p or -g.') > MODE = 'g' > # output: > elif arg == '-d' or arg == '--debug': DBG=True > elif arg == '-v' or arg == '--verbose': VRB=True > elif arg == '-q' or arg == '--quiet': QUIET=True > # help: > elif arg == '-h' or arg == '--help': usage() > else: usage('Invalid parameter "%s".'%arg) > >if not MODE: usage('You need to select the mode (-p or -g).') > >if QUIET: DBG, VRB = False, False >if VRB: > if MODE == 'p': print( 'MODE = PRETEND --> Will only print what would be removed from your DISTDIR.' ) > if MODE == 'g': print( 'MODE = GO --> Will *remove* files from your DISTDIR.' ) > >if not QUIET: print( 'DISTDIR = "%s"' % DISTDIR ) > >#### DOIT - COLLECT INFORMATION #### > >if not QUIET: print( '' ) # mark this block with an empty line > >vartree = portage.db['/']['vartree'] >packages = [] >for name in vartree.getallnodes(): > packages.extend(vartree.dep_match(name)) >if DBG: print( 'packages = [%s] %s' % (len(packages), packages) ) > >filesToKeep = {} >for package in packages: > try: > package_files = portage.portdb.getFetchMap(package) > if DBG: print( 'package "%s" --> package_files = [%s] %s' % (package, len(package_files), package_files.keys()) ) > for filename in package_files: > filesToKeep[filename] = 1 > except: > if not QUIET: print( 'WARNING: Failed to get file list for "%s"' % package ) >if DBG: print( 'filesToKeep = [%s] %s' % (len(filesToKeep), filesToKeep) ) > >if not filesToKeep: > sys.exit("No package files found. This can't be right.\n") > >try: > fileList = portage.listdir(DISTDIR) >except os.OSError: > sys.exit('Failed to read ' + DISTDIR) > >#### DOIT - GO THROUGH DISTDIR FILES AND DECIDE #### > >if not QUIET: print( '' ) # mark this block with an empty line >removedSize = 0; removedCount = 0 >keptSize = 0; keptCount = 0 >for filename in sorted(fileList): > abs_file = DISTDIR + '/' + filename > if not os.path.isfile(abs_file): > if DBG: print( 'Ignored NON-FILE "%s"' % abs_file ) > continue > if os.path.islink(abs_file): > if DBG: print( 'Ignored LINK "%s"' % abs_file ) > continue > > fileSize = os.stat(abs_file).st_size > if filename in filesToKeep: > if VRB: print( 'Kept file "%s" [%i KB]' % (filename, fileSize/1024) ) > keptSize += fileSize > keptCount += 1 > continue > > removedSize += fileSize > removedCount += 1 > if MODE == 'p': > if not QUIET: print( 'Would remove "%s" [%i KB]' % (abs_file, fileSize/1024) ) > else: > try: > os.remove(abs_file) > if not QUIET: print( 'Removed "%s" [%i KB]' % (abs_file, fileSize/1024) ) > except OSError: > if not QUIET: print( 'WARNING: Failed to remove "%s" [%i KB]' % (abs_file, fileSize/1024) ) > >#### DOIT - PRINT STATS #### > >if not QUIET: > removedSize /= 1048576 ## MB > keptSize /= 1048576 ## MB > if removedCount > 0: print('') > print( 'Removed: %6i files [%6i MB]\nKept : %6i files [%6i MB]' % (removedCount, removedSize, keptCount, keptSize) ) >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 371326
:
276856
|
276858