top of page
Screenshot from 2020-06-17 11-32-51.png

Scripting

Marcel's syntax was designed for interactive usage. Instead of extending this syntax to a full-fledged scripting language, marcel provides a Python API, allowing Python to be used as the scripting language. While Python is sometimes considered to already be a scripting language, it isn't really. Executing shell commands from Python code is cumbersome. You've got to use os.system, or subprocess.Popen, and write some additional code to do the integration.

Marcel provides a Python module, marcel.api, which brings shell commands into Python in a much cleaner way. For example, to list file names and sizes in /home/jao:

from marcel.api import *

for file, size in (ls('marcel',

                      'test',

                      file=True,

                      recursive=True) |

                   map(lambda f: (f.path, f.size))):

    print(f'{file}: {size}')

This code uses the ls and map functions, provided by marcel.api. These correspond to marcel operators that you can use on the command line. Output from ls is a stream of Files, which are piped to map, which maps Files to (file, file size) tuples. ls ... | map ... defines a pipeline (just as on the command line). The Python class representing pipelines defines __iter__, so that the pipeline's output can be iterated over using the standard Python for loop.

bottom of page