Skip to content

Instantly share code, notes, and snippets.

@clalancette
Created September 11, 2019 13:37
Show Gist options
  • Save clalancette/9ab2d0a345fee738d332d2509cfa7d88 to your computer and use it in GitHub Desktop.
Save clalancette/9ab2d0a345fee738d332d2509cfa7d88 to your computer and use it in GitHub Desktop.
Python script to remove dbgsym packages from ROS sync notices and recalculate package numbers
#!/usr/bin/python3
import sys
if len(sys.argv) != 3:
print("Usage: %s <input> <distro>" % (sys.argv[0]))
sys.exit(1)
infile = sys.argv[1]
distro = sys.argv[2]
ADDED = 1
UPDATED = 2
REMOVED = 3
state = None
num_added = 0
num_updated = 0
num_removed = 0
with open(infile, 'r') as infp:
for line in infp:
if line.startswith('### Added Packages'):
state = ADDED
elif line.startswith('### Updated Packages'):
state = UPDATED
elif line.startswith('### Removed Packages'):
state = REMOVED
elif line.startswith('Thanks to all ROS maintainers'):
state = None
if state in [ADDED, UPDATED, REMOVED]:
if line.startswith(' * ros-%s' % (distro)) or line.startswith(' * [ros-%s' % (distro)):
if 'dbgsym' in line:
continue
if state == ADDED:
num_added += 1
elif state == UPDATED:
num_updated += 1
elif state == REMOVED:
num_removed += 1
else:
# We are in a packages section, but the line didn't start
# with what we expected. This may just be an empty line,
# so just skip it.
pass
else:
# If we aren't yet in one of the packages sections, do nothing
pass
# Now that we have the correct count of packages, we need to do a second
# pass to fix up the package numbers
with open(infile, 'r') as infp:
for line in infp:
if line.startswith('### Added Packages'):
print('### Added Packages [%d]:' % (num_added))
elif line.startswith('### Updated Packages'):
print('### Updated Packages [%d]:' % (num_updated))
elif line.startswith('### Removed Packages'):
print('### Removed Packages [%d]:' % (num_removed))
else:
if line.startswith(' * ros-%s' % (distro)) or line.startswith(' * [ros-%s' % (distro)):
if 'dbgsym' in line:
continue
print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment