kadischi/lib functions.py,1.5,1.6
Jasper O'neal Hartline (autopsy)
fedora-extras-commits at redhat.com
Fri Mar 31 21:03:38 UTC 2006
Author: autopsy
Update of /cvs/devel/kadischi/lib
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25007/kadischi/lib
Modified Files:
functions.py
Log Message:
Contributor: Toshio Kuratomi (Consistency between spaces vs. tabs), commit
Index: functions.py
===================================================================
RCS file: /cvs/devel/kadischi/lib/functions.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- functions.py 30 Mar 2006 04:29:21 -0000 1.5
+++ functions.py 31 Mar 2006 21:03:36 -0000 1.6
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python -tt
import os
import sys
@@ -12,125 +12,125 @@
import isys
def normalize_path (parts, rootpath = None):
- if rootpath == None:
- rootpath = '/'
- path = rootpath
- for part in parts:
- path = '/'.join([path, part])
- return os.path.normpath (path)
+ if rootpath == None:
+ rootpath = '/'
+ path = rootpath
+ for part in parts:
+ path = '/'.join([path, part])
+ return os.path.normpath (path)
def path_exists (path, quiet = False):
- if os.path.exists (path):
- if not quiet:
- flc_log ('Path %s exists. OK' % path)
- return True
- else:
- if not quiet:
- flc_log ('Error - path %s doesn`t exist.' % path)
- return False
+ if os.path.exists (path):
+ if not quiet:
+ flc_log ('Path %s exists. OK' % path)
+ return True
+ else:
+ if not quiet:
+ flc_log ('Error - path %s doesn`t exist.' % path)
+ return False
def url_exists (url, quiet = False):
- try:
- u = grabber.urlopen (url, retry = 5)
- if not quiet:
- flc_log ('URL %s contacted. OK' % url)
- u.close ()
- return True
- except grabber.URLGrabError, e:
- if not quiet:
- flc_log ("An error occurred contacting %s." % url)
- flc_log ("URLGrabError:\n %s" % e.strerror)
- return False
+ try:
+ u = grabber.urlopen (url, retry = 5)
+ if not quiet:
+ flc_log ('URL %s contacted. OK' % url)
+ u.close ()
+ return True
+ except grabber.URLGrabError, e:
+ if not quiet:
+ flc_log ("An error occurred contacting %s." % url)
+ flc_log ("URLGrabError:\n %s" % e.strerror)
+ return False
def clear_rpm_db_files (rootdir):
- """Removes rpm database files in the destination if they exist"""
- def rmpath (p):
- try: os.remove (p)
- except OSError: pass
- rmpath (normalize_path ('var/lib/rpm/__db.001', rootdir))
- rmpath (normalize_path ('var/lib/rpm/__db.002', rootdir))
- rmpath (normalize_path ('var/lib/rpm/__db.003', rootdir))
-
+ """Removes rpm database files in the destination if they exist"""
+ def rmpath (p):
+ try: os.remove (p)
+ except OSError: pass
+ rmpath (normalize_path ('var/lib/rpm/__db.001', rootdir))
+ rmpath (normalize_path ('var/lib/rpm/__db.002', rootdir))
+ rmpath (normalize_path ('var/lib/rpm/__db.003', rootdir))
+
def check_installed_rpms (rootdir, required_rpms, clear_db = True):
- """Sanity check the target system for required RPMs"""
- # By default, clears out the db files before and after doing any operations
- missing_rpms = []
- if clear_db:
- clear_rpm_db_files (rootdir)
- ts = rpm.TransactionSet (rootdir)
- for package in required_rpms:
- mi = ts.dbMatch ('name', package)
- if mi.count () == 0:
- missing_rpms.append (package)
- if clear_db:
- clear_rpm_db_files (rootdir)
- return missing_rpms
+ """Sanity check the target system for required RPMs"""
+ # By default, clears out the db files before and after doing any operations
+ missing_rpms = []
+ if clear_db:
+ clear_rpm_db_files (rootdir)
+ ts = rpm.TransactionSet (rootdir)
+ for package in required_rpms:
+ mi = ts.dbMatch ('name', package)
+ if mi.count () == 0:
+ missing_rpms.append (package)
+ if clear_db:
+ clear_rpm_db_files (rootdir)
+ return missing_rpms
def get_kernel_version (rootdir):
- kernel_version = None
- clear_rpm_db_files (rootdir)
- ts = rpm.TransactionSet (rootdir)
- while kernel_version == None:
- if isys.smpAvailable() or isys.htavailable():
- for mi in ts.dbMatch ('name', 'kernel-xen0'):
- kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'xen0'
- clear_rpm_db_files (rootdir)
- for mi in ts.dbMatch ('name', 'kernel-smp'):
- kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'smp'
- clear_rpm_db_files (rootdir)
- else:
- for mi in ts.dbMatch ('name', 'kernel-xen0'):
- kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'xen0'
- clear_rpm_db_files (rootdir)
- for mi in ts.dbMatch ('name', 'kernel'):
- kernel_version = "%s-%s" % (mi['version'], mi['release'])
- clear_rpm_db_files (rootdir)
- return kernel_version
+ kernel_version = None
+ clear_rpm_db_files (rootdir)
+ ts = rpm.TransactionSet (rootdir)
+ while kernel_version == None:
+ if isys.smpAvailable() or isys.htavailable():
+ for mi in ts.dbMatch ('name', 'kernel-xen0'):
+ kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'xen0'
+ clear_rpm_db_files (rootdir)
+ for mi in ts.dbMatch ('name', 'kernel-smp'):
+ kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'smp'
+ clear_rpm_db_files (rootdir)
+ else:
+ for mi in ts.dbMatch ('name', 'kernel-xen0'):
+ kernel_version = "%s-%s" % (mi['version'], mi['release']) + 'xen0'
+ clear_rpm_db_files (rootdir)
+ for mi in ts.dbMatch ('name', 'kernel'):
+ kernel_version = "%s-%s" % (mi['version'], mi['release'])
+ clear_rpm_db_files (rootdir)
+ return kernel_version
def clean_directory (dir, remove_when_done=True, keep_child_directories=False):
- """Removes all files in a directory, optionally removing the directory afterwards"""
- assert os.path.isdir and not os.path.islink (dir)
- file_list = os.listdir (dir)
-
- for f in file_list:
- path = os.path.join (dir, f)
- if os.path.isdir (path) and not os.path.islink (path):
- clean_directory (path,
- not keep_child_directories,
- keep_child_directories)
- else:
- os.remove (path)
+ """Removes all files in a directory, optionally removing the directory afterwards"""
+ assert os.path.isdir and not os.path.islink (dir)
+ file_list = os.listdir (dir)
+
+ for f in file_list:
+ path = os.path.join (dir, f)
+ if os.path.isdir (path) and not os.path.islink (path):
+ clean_directory (path,
+ not keep_child_directories,
+ keep_child_directories)
+ else:
+ os.remove (path)
- if remove_when_done:
- os.rmdir (dir)
+ if remove_when_done:
+ os.rmdir (dir)
def sysconfig_file (rootdir, name):
- path = normalize_path(['/etc/sysconfig/', name], rootdir)
- return shvar.shvarFile (path)
+ path = normalize_path(['/etc/sysconfig/', name], rootdir)
+ return shvar.shvarFile (path)
def flc_log (msg):
- sys.stdout.write (msg + '\n')
+ sys.stdout.write (msg + '\n')
def cleanup (builddir):
- os.system ("umount %s 2>/dev/null" % normalize_path(['/system/proc'],builddir))
- if os.path.exists (normalize_path([builddir,'product'])):
- clean_directory ('/tmp/product')
- shutil.move (normalize_path([builddir,'product']), '/tmp/product')
- elif os.path.exists (normalize_path([builddir,'.buildstamp'])):
- os.unlink ('/tmp/product/.buildstamp')
- shutil.move (normalize_path([builddir,'.buildstamp']), '/tmp/product/.buildstamp')
- else:
- os.unlink ('/tmp/product/.buildstamp')
- clean_directory (builddir)
-
+ os.system ("umount %s 2>/dev/null" % normalize_path(['/system/proc'],builddir))
+ if os.path.exists (normalize_path([builddir,'product'])):
+ clean_directory ('/tmp/product')
+ shutil.move (normalize_path([builddir,'product']), '/tmp/product')
+ elif os.path.exists (normalize_path([builddir,'.buildstamp'])):
+ os.unlink ('/tmp/product/.buildstamp')
+ shutil.move (normalize_path([builddir,'.buildstamp']), '/tmp/product/.buildstamp')
+ else:
+ os.unlink ('/tmp/product/.buildstamp')
+ clean_directory (builddir)
+
def run (command, builddir = None):
- rc = os.system (command)
- if rc != 0:
- flc_log ('\n *** Fatal error: %s returned non zero (%s) exit code. Aborting execution.\n' % (command.rsplit() [0], rc))
- if builddir != None:
- flc_log ('Cleaning up temporary files...')
- cleanup (builddir)
- flc_log ('Done.')
- else:
- flc_log ('You should clean temporary files.')
- sys.exit (1)
+ rc = os.system (command)
+ if rc != 0:
+ flc_log ('\n *** Fatal error: %s returned non zero (%s) exit code. Aborting execution.\n' % (command.rsplit() [0], rc))
+ if builddir != None:
+ flc_log ('Cleaning up temporary files...')
+ cleanup (builddir)
+ flc_log ('Done.')
+ else:
+ flc_log ('You should clean temporary files.')
+ sys.exit (1)
More information about the fedora-extras-commits
mailing list