Skip to content

Commit

Permalink
upstream_rebuilds.py: Use apt library instead of system calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Nov 13, 2024
1 parent 8e39c0e commit d0e846e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/scripts/upstream_rebuilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from dataclasses import dataclass, field
from pathlib import Path
import argparse
import apt
import datetime
import subprocess
import os, re


Expand Down Expand Up @@ -50,6 +50,9 @@ class Options:

view = lookup.get_rosdep_view(DEFAULT_VIEW_KEY, verbose=options.verbose)

apt_cache = apt.Cache()
apt_cache.open()


def resolve(rosdep_name):
"Resolve rosdep package name to required system package name(s)"
Expand All @@ -75,10 +78,7 @@ def stamp(pkg_name):
if not deb_name.startswith("ros-"):
return datetime.datetime.fromtimestamp(0)

# run shell command: LANG=C apt-cache policy "$1" | sed -n "s#^\s*Candidate:\s\(.*\)#\1#p"
candidate = subprocess.getoutput(
f'apt-cache policy "{deb_name}" | sed -n "s#^\\s*Candidate:\\s\\(.*\\)#\\1#p"'
)
candidate = apt_cache[deb_name].candidate.version
result = regex.match(candidate).groupdict()
return datetime.datetime.strptime(result["stamp"], "%Y%m%d.%H%M")
except IndexError:
Expand Down

0 comments on commit d0e846e

Please sign in to comment.