mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-30 06:11:26 -07:00
Refactor computation of archive filenames, clearer archive filename
This commit is contained in:
parent
87c8a21d16
commit
51ab6cdc0d
1 changed files with 11 additions and 12 deletions
|
@ -231,36 +231,35 @@ def main():
|
||||||
|
|
||||||
for path in archive_paths:
|
for path in archive_paths:
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
basename = ''
|
|
||||||
|
|
||||||
# Prefix trees in the archive with their basename, unless specifically prevented with '.'
|
|
||||||
if not path.endswith(os.sep + '.'):
|
|
||||||
basename = os.path.basename(path) + os.sep
|
|
||||||
|
|
||||||
# Recurse into directories
|
# Recurse into directories
|
||||||
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
|
for dirpath, dirnames, filenames in os.walk(path, topdown=True):
|
||||||
|
if not dirpath.endswith(os.sep):
|
||||||
|
dirpath += os.sep
|
||||||
|
|
||||||
for dirname in dirnames:
|
for dirname in dirnames:
|
||||||
fullpath = dirpath + os.sep + dirname
|
fullpath = dirpath + dirname
|
||||||
|
arcname = fullpath[len(arcroot):]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if compression == 'zip':
|
if compression == 'zip':
|
||||||
arcfile.write(fullpath, basename + dirname)
|
arcfile.write(fullpath, arcname)
|
||||||
else:
|
else:
|
||||||
arcfile.add(fullpath, basename + dirname, recursive=False)
|
arcfile.add(fullpath, arcname, recursive=False)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
errors.append('%s: %s' % (fullpath, str(e)))
|
errors.append('%s: %s' % (fullpath, str(e)))
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
fullpath = dirpath + os.sep + filename
|
fullpath = dirpath + filename
|
||||||
|
arcname = fullpath[len(arcroot):]
|
||||||
|
|
||||||
if not filecmp.cmp(fullpath, dest):
|
if not filecmp.cmp(fullpath, dest):
|
||||||
try:
|
try:
|
||||||
if compression == 'zip':
|
if compression == 'zip':
|
||||||
arcfile.write(fullpath, basename + filename)
|
arcfile.write(fullpath, arcname)
|
||||||
else:
|
else:
|
||||||
arcfile.add(fullpath, basename + filename, recursive=False)
|
arcfile.add(fullpath, arcname, recursive=False)
|
||||||
|
|
||||||
successes.append(fullpath)
|
successes.append(fullpath)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue