Changeset a2e54d9 in rattail


Ignore:
Timestamp:
10/31/2022 08:52:06 PM (3 months ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
5900035
Parents:
5bcc3ba
Message:

Add workaround for shlex.join() prior to python 3.8

Location:
rattail
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/luigi/handler.py

    r5bcc3ba ra2e54d9  
    2929import os
    3030import logging
    31 import shlex
    3231import subprocess
    3332import sys
     
    3837
    3938from rattail.app import GenericHandler
     39from rattail.util import shlex_join
    4040
    4141
     
    133133               cmd]
    134134
    135         cmd = ['echo', shlex.join(cmd)]
    136         cmd = shlex.join(cmd)
     135        cmd = ['echo', shlex_join(cmd)]
     136        cmd = shlex_join(cmd)
    137137
    138138        cmd = "{} | at 'now + 1 minute'".format(cmd)
     
    221221               'run-n-mail',
    222222               '-S', 'Backfill thru {}: {}'.format(last_date, task['description']),
    223                shlex.join(cmd)]
    224 
    225         cmd = ['echo', shlex.join(cmd)]
    226         cmd = shlex.join(cmd)
     223               shlex_join(cmd)]
     224
     225        cmd = ['echo', shlex_join(cmd)]
     226        cmd = shlex_join(cmd)
    227227
    228228        cmd = "{} | at 'now + 1 minute'".format(cmd)
  • rattail/util.py

    r5bcc3ba ra2e54d9  
    2828from __future__ import division
    2929
     30import shlex
    3031import sys
    3132import datetime
     
    365366        return "{}: {}".format(cls, msg)
    366367    return cls
     368
     369
     370def shlex_join(split_command):
     371    """
     372    Wrapper which invokes ``shlex.join()`` if available; otherwise
     373    a workaround is implemented.
     374
     375    cf. https://stackoverflow.com/a/50022816
     376    """
     377    if hasattr(shlex, 'join'):
     378        return shlex.join(split_command)
     379
     380    return ' '.join(shlex.quote(x) for x in split_command)
Note: See TracChangeset for help on using the changeset viewer.