I tested to see what would happen with each if the options (-G -B -P
-S -I) and I found out that on G,B and I tracedback, in the other
options it didn't. When I tested again (I don't know why I tested two
times), I found that the tracebacks where different in G, B and I. So
basically the trace backs depend on the state of the directory. If
the directory is in one state the traceback happens in one line, if it
is in another state it has the possibility of occurring in another.
So I thought that the best way to fix it would be to check for the
existence of the directory in every directory creation, so I looked
for every occurrence of "os.makedirs":
/usr/lib/python2.5/site-packages/pypungi/gather.py:64:
os.makedirs(logdir)
/usr/lib/python2.5/site-packages/pypungi/gather.py:275:
os.makedirs(pkgdir)
/usr/lib/python2.5/site-packages/pypungi/gather.py:342:
os.makedirs(pkgdir)
/usr/lib/python2.5/site-packages/pypungi/pungi.py:45:
os.makedirs(self.workdir)
/usr/lib/python2.5/site-packages/pypungi/pungi.py:165:
os.makedirs(docsdir)
/usr/lib/python2.5/site-packages/pypungi/pungi.py:263:
os.makedirs("%s-disc%d/SRPMS" % (timber.dist_dir, i))
/usr/lib/python2.5/site-packages/pypungi/pungi.py:293:
os.makedirs('%s-disc1' % self.topdir)
/usr/lib/python2.5/site-packages/pypungi/pungi.py:320:
os.makedirs(self.isodir)
/usr/bin/pungi:90: os.makedirs(destdir)
/usr/bin/pungi:99: os.makedirs(cachedir)
Actually more lines must be changed. All the shutils lines that create
a directory in one way or another have the potential to traceback with
the "directory already exists" message.
I just don't like it... IMO its just not right to check for the
existence of the directory in every line!!!
So I take what I said in my last post back, and am sticking with the
"create a new root directory for each execution" solution. I changed
it a little. Instead of using time.time(), I used time.localtime()'s
elements. So now the directory would be something like
"/srv/pungi/Fedora/2007-5-16-1430/..." IMO it looks much better than
what time.time() spits out.
Considering the state of pungi in which it is separated
by stages this
^^^^^ solution is not really very useful :(. An option in which the
user selects the name of the tree he wants to use is needed (not pretty).
Came up with another solution that until now has pretty much solved the
problem and has not broken pungi (in my tests). The solutions simply
clears any directory that pungi is going to create. So for each line in
which a directory is created I added a line to erase it.
The diff is attached.
Regards.
--
Joel Andres Granados
diff --git a/pypungi/gather.py b/pypungi/gather.py
index 52a5f03..67048ae 100755
--- a/pypungi/gather.py
+++ b/pypungi/gather.py
@@ -305,6 +305,7 @@ class Gather(yum.YumBase):
target = os.path.join(pkgdir, os.path.basename(remote))
if os.path.exists(target):
os.remove(target) # avoid traceback after interrupted download
+ if os.path.isfile(target):os.remove(target)#make sure to refresh
os.link(local, target)
continue
@@ -319,7 +320,9 @@ class Gather(yum.YumBase):
if not os.path.exists(local) or not os.path.samefile(path, local):
shutil.copy2(path, local)
- os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
+ target = os.path.join(pkgdir, os.path.basename(remote))
+ if os.path.isfile(target): os.remove(target)#make sure to refresh
+ os.link(local, target)
def downloadSRPMs(self):
@@ -368,11 +371,14 @@ class Gather(yum.YumBase):
if not self.config.has_option('default', 'quiet'):
self.logger.info("%s already exists and appears to be
complete" % local)
- if os.path.exists(os.path.join(pkgdir, os.path.basename(remote))) and
self.verifyCachePkg(pkg, os.path.join(pkgdir, os.path.basename(remote))) ==
pkg.packagesize:
+ if os.path.exists(os.path.join(pkgdir, os.path.basename(remote))) and \
+ self.verifyCachePkg(pkg, os.path.join(pkgdir,
os.path.basename(remote))) == pkg.packagesize:
if not self.config.has_option('default', 'quiet'):
self.logger.info("%s already exists in tree and appears to
be complete" % local)
else:
- os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
+ target = os.path.join(pkgdir, os.path.basename(remote))
+ if os.path.isfile(target): os.remove(target)
+ os.link(local, target)
continue
# Disable cache otherwise things won't download
@@ -386,4 +392,6 @@ class Gather(yum.YumBase):
if not os.path.exists(local) or not os.path.samefile(path, local):
shutil.copy2(path, local)
- os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
+ target = os.path.join(pkgdir, os.path.basename(remote))
+ if os.path.isfile(target): os.remove(target)
+ os.link(local, target)
diff --git a/pypungi/pungi.py b/pypungi/pungi.py
index 3f74669..2389131 100755
--- a/pypungi/pungi.py
+++ b/pypungi/pungi.py
@@ -162,7 +162,8 @@ class Pungi:
for pattern in self.config.get('default',
'relnotedirre').split():
dirres.append(re.compile(pattern))
- os.makedirs(docsdir)
+ if not os.path.exists(docsdir):
+ os.makedirs(docsdir)
# Expload the packages we list as relnote packages
pkgs = os.listdir(os.path.join(self.topdir, self.config.get('default',
'product_path')))
@@ -201,7 +202,9 @@ class Pungi:
for regex in dirres:
if regex.match(directory) and not
os.path.exists(os.path.join(self.topdir, directory)):
log.info("Copying release note dir %s" % directory)
- shutil.copytree(os.path.join(dirpath, directory),
os.path.join(self.topdir, directory))
+ target = os.path.join(self.topdir, directory)
+ shutil.rmtree(target, ignore_errors=True)
+ shutil.copytree(os.path.join(dirpath, directory), target)
def doSplittree(self):
@@ -260,10 +263,11 @@ class Pungi:
# this is stolen from splittree.py in anaconda-runtime. Blame them if its ugly
(:
for i in range(timber.src_list[0], timber.src_list[-1] + 1):
+ if not os.path.exists("%s-disc%d/SRPMS" % (timber.dist_dir, i)):
os.makedirs("%s-disc%d/SRPMS" % (timber.dist_dir, i))
- timber.linkFiles(timber.dist_dir,
- "%s-disc%d" %(timber.dist_dir, i),
- timber.common_files)
+ timber.linkFiles(timber.dist_dir,
+ "%s-disc%d" %(timber.dist_dir, i),
+ timber.common_files)
timber.splitSRPMS()
log.info("splitSRPMS complete")
@@ -289,7 +293,8 @@ class Pungi:
createrepo.append('media://%s' % mediaid)
createrepo.append('--outputdir')
- if self.config.getint('default', 'discs') == 1:
+ if self.config.getint('default', 'discs') == 1 and \
+ not os.path.exists('%s-disc1' % self.topdir):
os.makedirs('%s-disc1' % self.topdir)
createrepo.append('%s-disc1' % self.topdir)
@@ -317,7 +322,8 @@ class Pungi:
anaruntime = '/usr/lib/anaconda-runtime/boot'
discinfofile = os.path.join(self.topdir, '.discinfo') # we use this a
fair amount
- os.makedirs(self.isodir)
+ if not os.path.exists(self.isodir):
+ os.makedirs(self.isodir)
# setup the base command
mkisofs = ['/usr/bin/mkisofs']
@@ -401,9 +407,10 @@ class Pungi:
content[content.index('ALL\n')] = ','.join([str(x) for x
in range(1, self.config.getint('default', 'discs') + 1)]) + '\n'
open(discinfofile, 'w').writelines(content)
- # move the main repodata out of the way to use the split repodata
- shutil.move(os.path.join(self.topdir, 'repodata'),
os.path.join(self.config.get('default', 'destdir'),
- 'repodata-%s' % self.config.get('default',
'arch')))
+ # move the main repodata directory out of the way to use the split
repodata
+ target = os.path.join(self.config.get('default',
'destdir'), 'repodata-%s' % self.config.get('default',
'arch'))
+ shutil.rmtree(target, ignore_errors=True)
+ shutil.move(os.path.join(self.topdir, 'repodata'), target)
shutil.copytree('%s-disc1/repodata' % self.topdir,
os.path.join(self.topdir, 'repodata'))
# setup the extra mkisofs args
@@ -448,9 +455,10 @@ class Pungi:
# return the .discinfo file
if not self.config.get('default', 'arch') ==
'source':
- shutil.move(os.path.join(self.config.get('default',
'destdir'), '.discinfo-%s' % self.config.get('default',
'arch')), discinfofile)
+ shutil.move(os.path.join(self.config.get('default',
'destdir'),
+ '.discinfo-%s' % self.config.get('default',
'arch')), discinfofile)
- shutil.rmtree(os.path.join(self.topdir, 'repodata')) # remove our
copied repodata
+ shutil.rmtree(os.path.join(self.topdir, 'repodata'),
ignore_errors=True) # remove our copied repodata
shutil.move(os.path.join(self.config.get('default',
'destdir'),
'repodata-%s' % self.config.get('default',
'arch')), os.path.join(self.topdir, 'repodata'))
@@ -512,6 +520,7 @@ class Pungi:
for directory in dirs:
if directory.startswith('os-disc') or
directory.startswith('SRPM-disc'):
+ shutil.rmtree(os.path.join(self.workdir,directory), ignore_errors=True)
shutil.move(os.path.join(self.archdir, directory),
os.path.join(self.workdir, directory))
log.info("CreateIsos is done.")