extras-buildsys/utils/pushscript Utils.py,1.24,1.25
Michael Schwendt
mschwendt at fedoraproject.org
Thu Nov 6 12:08:38 UTC 2008
Author: mschwendt
Update of /cvs/fedora/extras-buildsys/utils/pushscript
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv29569
Modified Files:
Utils.py
Log Message:
- change the createrepo helpers to support the separate repo tree layout for dist 'development'
- add another makedir for from-scratch setups
- drop the incomplete DEBUG flag usage
Index: Utils.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/utils/pushscript/Utils.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Utils.py 24 Oct 2007 20:09:04 -0000 1.24
+++ Utils.py 6 Nov 2008 12:08:38 -0000 1.25
@@ -27,27 +27,13 @@
ts = rpmUtils.transaction.initReadOnlyTransaction()
-DEBUG = False
-
-def setdebug(onoff):
- global DEBUG
- DEBUG = onoff
-
-def debugprint(msg):
- if DEBUG:
- print ' DEBUG:', msg
-
def run(cmd):
- debugprint(cmd)
- if not DEBUG:
- result = os.system(cmd)
- if result != 0:
- print >> sys.stderr, 'Error running command: %s ' % cmd
- if result > 127:
- return 1
- return result
- else:
- return 0
+ result = os.system(cmd)
+ if result != 0:
+ print >> sys.stderr, 'Error running command: %s ' % cmd
+ if result > 127:
+ return 1
+ return result
def run_and_check(cmd):
result = run(cmd)
@@ -104,9 +90,7 @@
if not overwrite and os.path.exists(dest):
print('WARNING: %s already exists, ignoring new one' % dest)
return
- debugprint('Copying %s to %s' % (src,dest))
- if not DEBUG:
- shutil.copy2(src,dest)
+ shutil.copy2(src,dest)
def install_move(src,dest,overwrite=False):
@@ -114,9 +98,7 @@
if not overwrite and os.path.exists(dest):
print('WARNING: %s already exists, ignoring new one' % dest)
return
- debugprint('Moving %s to %s' % (src,dest))
- if not DEBUG:
- shutil.move(src,dest)
+ shutil.move(src,dest)
def install_link(src,dest):
@@ -124,9 +106,7 @@
if os.path.exists(dest):
print('WARNING: %s already exists, ignoring new one' % dest)
return
- debugprint('Linking %s <- %s' % (src,dest))
- if not DEBUG:
- os.link(src,dest)
+ os.link(src,dest)
def install_link_or_copy(src,dest):
@@ -141,7 +121,8 @@
install_copy(src,dest)
-def _create_repository(cfg,dist,repodir,debuginfo=True):
+def _create_repository(cfg,dist,repodir,debuginfo=False):
+ # debuginfo: False=exclude debuginfo packages in debug subdir
print 'Creating repository %s' % repodir
cmd = cfg.createrepo
@@ -149,7 +130,7 @@
cmd = cfg.createrepo_dict.get(dist,cmd)
if os.path.exists( os.path.join(repodir,compsname) ):
cmd += ' -g %s' % compsname
- if debuginfo and os.path.exists( os.path.join(repodir,'debug') ):
+ if (not debuginfo) and os.path.exists( os.path.join(repodir,'debug') ):
cmd += " -x \'*debuginfo*\'"
cachedir = os.path.join(cfg.cr_cachedir,dist)
if not os.path.exists(cachedir):
@@ -173,7 +154,9 @@
shutil.move(sourcefile,targetfile)
-def _backup_create_repository(cfg,dist,repodir,debuginfo):
+def create_repository(cfg,dist,repodir,debuginfo=False):
+ """create/update repository metadata for a given directory and
+ exclude debuginfo packages in a 'debug' sub-repository by default"""
# Create dirs, if missing, so we would create empty backups, too.
rpdata = os.path.join(repodir,'repodata')
for d in [repodir,rpdata]:
@@ -206,18 +189,6 @@
sys.exit(errno.EPERM)
-def create_repository(cfg,dist,repodir,debuginfo=True):
- """create/update repository metadata for a given directory and
- consider a 'debug' sub-repository by default"""
-
- _backup_create_repository(cfg,dist,repodir,debuginfo)
-
- dbg_repodir = os.path.join(repodir, 'debug')
- # If there's a debug subdir, make that a repo, too.
- if debuginfo and os.path.exists(dbg_repodir):
- _backup_create_repository(cfg,dist,dbg_repodir,False)
-
-
def is_repo_changed(repodir):
"""Checks if the repository has changed and needs to be reindexed"""
ref_file = os.path.join(repodir, 'repodata', 'repomd.xml')
@@ -249,29 +220,60 @@
return False
-def is_any_repo_changed(cfg,dist,reporoot):
+def is_any_repo_changed(cfg,dist,reporoot=None):
+ """Check a repository and its sub-repositories for external changes
+ such as file removals."""
for repodir in get_std_repodirs(cfg,dist,reporoot):
+ if not os.path.exists(repodir):
+ return True
if is_repo_changed(repodir):
- debugprint("Dist %s (%s) was changed" % (dist, repodir))
+ #print("Dist %s (%s) was changed" % (dist, repodir))
return True
return False
-def get_std_repodirs(cfg,dist,reporoot):
+def get_std_repodirs(cfg,dist,reporoot=None):
"""return list of all repository directories (below reporoot) for
this distribution version"""
- repodirs = [os.path.join(reporoot,'SRPMS')]
+ repodirs = [ srpm_repodir(cfg,dist,reporoot) ]
for arch in cfg.archdict[dist]:
- repodirs.append(os.path.join(reporoot,arch))
- repodirs.append(os.path.join(reporoot,arch,'debug'))
+ repodirs.append( rpm_repodir(cfg,dist,arch,reporoot) )
+ repodirs.append( debug_repodir(cfg,dist,arch,reporoot) )
return repodirs
-def make_std_repodirs(cfg,dist,reporoot):
+def srpm_repodir(cfg,dist,reporoot=None):
+ if not reporoot:
+ reporoot = os.path.join(cfg.treedir,dist)
+ if dist == 'development': # hack for rawhide/releases repo path scheme
+ srpmspath = os.path.join(reporoot,'source/SRPMS')
+ else: # old Extras/EPEL/updates/testing scheme
+ srpmspath = os.path.join(reporoot,'SRPMS')
+ return srpmspath
+
+
+def rpm_repodir(cfg,dist,arch,reporoot=None):
+ if not reporoot:
+ reporoot = os.path.join(cfg.treedir,dist)
+ if dist == 'development': # hack for rawhide/releases repo path scheme
+ rpmspath = os.path.join(reporoot,'$arch/os')
+ else: # old Extras/EPEL/updates/testing scheme
+ rpmspath = os.path.join(reporoot,'$arch')
+ return rpmspath.replace('$arch',arch)
+
+
+def debug_repodir(cfg,dist,arch,reporoot=None):
+ if not reporoot:
+ reporoot = os.path.join(cfg.treedir,dist)
+ debugrpmspath = os.path.join(reporoot,'$arch/debug')
+ return debugrpmspath.replace('$arch',arch)
+
+
+def make_std_repodirs(cfg,dist,reporoot=None):
"""create all repository directories (below reporoot) for
this distribution version, if they don't exist"""
for repodir in get_std_repodirs(cfg,dist,reporoot):
- if not DEBUG and not os.path.exists(repodir):
+ if not os.path.exists(repodir):
os.makedirs(repodir)
@@ -285,11 +287,16 @@
# become the owner of all files, then remove the copied tree and fix
# up directory modes. For this to work flawlessly, all files must be
# readable by our group.
+ if not os.path.exists(workdir):
+ os.makedirs(workdir)
try:
tmpdir = tempfile.mkdtemp('','.mdcache.tmp',workdir)
if tmpdir == workdir: # paranoid, should never happen
raise Exception
- except:
+ except OSError, e:
+ print e
+ sys.exit(errno.EIO)
+ except Exception:
sys.exit(errno.EIO)
if os.path.isdir(cachedir):
tmpcachedir = os.path.join(tmpdir,'mdcache')
@@ -353,9 +360,7 @@
fname = os.path.join(pkgrelroot,flag)
if os.path.isfile(fname):
return
- if DEBUG:
- print 'Creating %s' % fname
- return
+ #print 'Creating %s' % fname
try:
f = open(fname,'w')
f.close()
@@ -368,9 +373,7 @@
fname = os.path.join(pkgrelroot,flag)
if not os.path.isfile(fname):
return
- if DEBUG:
- print 'Deleting %s' % fname
- return
+ #print 'Deleting %s' % fname
os.remove(fname)
More information about the fedora-extras-commits
mailing list