Code Monkey home page Code Monkey logo

unpython's Introduction

unpython

Un-pythons a python subprocess command+arguments list back into CLI-friendly form.

Python scripts that deal with subprocess module usually need to prepare a list of string arguments for use with subprocess.run() (or similar). Sometimes you need to perform some quick n' dirty print() debugging to inspect the contents of that list. Or you may observe such lists being printed in production system logs. Any case, you might want to run the underlying command manually to verify whether it works as expected. But now you have to somehow "peel off" the pythonic list notation so that you can run the underlying command in a terminal.

You might get away doing the massaging by hand, although that becomes really annoying really fast. And it is also very error prone; you need to know how to handle spaces and quotation correctly. Not fun.

You could, of course, use the built-in shlex module to convert the list into CLI-safe form before printing. That's what this tool does too. However, sometimes the code that does the printing might be outside of your control...

Alternatively, you can use this tool for doing the conversion for you automatically. You only need to copy-paste the command list into the interactive prompt, and you will receive a valid, CLI-friendly command string in return :)

As you might notice, the functionality of this tool is rather simple; the goal of this repo is to provide the functionality in an easily installable package (especially if you use pipx).

Install

$ pip install --user git+https://github.com/MawKKe/unpython

I recommend using pipx:

$ pipx install git+https://github.com/MawKKe/unpython

just make sure that pipx is configured correctly (i.e. installed programs are available in your $PATH).

Usage

Run the program , then copy-paste your python list object into the prompt:

$ unpython
...
>>> ['ls', '-l', 'foo/bar with spaces']

now it should print

ls -l 'foo/bar with spaces'

You can then copy this output into a terminal to run your command the usual way. The unpython should handle quotation etc. correctly for you.

License

Copyright 2024 Markus Holmström (MawKKe)

The works under this repository are licenced under Apache License 2.0. See file LICENSE for more information.

Contributing

This project is hosted at https://github.com/MawKKe/unpython

You are welcome to leave bug reports, fixes and feature requests. Thanks!

unpython's People

Contributors

mawkke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.