Skip to content

Commit

Permalink
Address invalid escape sequences in strings
Browse files Browse the repository at this point in the history
The backslash character is an escape sequence in Python strings. These
strings contain backslashes which do not intend to escape the following
character, but rather include the backslash in the string.

There are two possible resolutions:
1. Make the string a "raw" string by prefixing it with "r". This
   effectively makes backslashes into a normal character.
2. Escape the backslashes with another backslash.

I used both approaches in this change where appropriate.
  • Loading branch information
cottsay committed Feb 8, 2024
1 parent 4a57612 commit 87a019c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions colcon_hardware_acceleration/subverb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def mount_rawimage(rawimage_path, partition=1, debug=False):

# fetch UNITS
units = None
cmd = "fdisk -l " + rawimage_path + " | grep 'Units\|Unidades' | awk '{print $8}'"
cmd = "fdisk -l " + rawimage_path + " | grep 'Units\\|Unidades' | awk '{print $8}'"
outs, errs = run(cmd, shell=True)
if outs:
units = int(outs)
Expand Down Expand Up @@ -682,7 +682,7 @@ def copy_colcon_workspace(install_dir): # noqa: D102

# fetch UNITS
units = None
cmd = "fdisk -l " + rawimage_path + " | grep 'Units\|Unidades' | awk '{print $8}'"
cmd = "fdisk -l " + rawimage_path + " | grep 'Units\\|Unidades' | awk '{print $8}'"
outs, errs = run(cmd, shell=True)
if outs:
units = int(outs)
Expand Down Expand Up @@ -921,7 +921,7 @@ def fix_yocto_honister(partition=2): # noqa: D102
- /etc/profile.d/ros/setup.sh and
- /usr/bin/ros_setup.bash
"""
content_etc_profile = """
content_etc_profile = r"""
# generated from ament_package/template/prefix_level/setup.sh.in
# since this file is sourced use either the provided AMENT_CURRENT_PREFIX
Expand Down Expand Up @@ -1068,7 +1068,7 @@ def fix_yocto_honister(partition=2): # noqa: D102
unset AMENT_SHELL
"""

content_usr_bin = """
content_usr_bin = r"""
# copied from ament_package/template/prefix_level/setup.bash
AMENT_SHELL=bash
Expand Down
2 changes: 1 addition & 1 deletion colcon_hardware_acceleration/subverb/emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def prepare_emulation(self, context): # noqa: D102
cmd = (
"fdisk -l "
+ rawimage_path
+ " | grep 'Units\|Unidades' | awk '{print $8}'"
+ " | grep 'Units\\|Unidades' | awk '{print $8}'"
)
outs, errs = run(cmd, shell=True)
if outs:
Expand Down

0 comments on commit 87a019c

Please sign in to comment.