Scripting

A simple form of scripting is to just write marcel commands in a text file. From an ordinary shell, you can execute this script by redirecting it to the marcel executable, e.g. marcel < script.marcel.

A more powerful form of scripting can be done from Python, using the marcel.api module. With this module, you have access to the operators of marcel, neatly integrated into Python. For example, here is the "recent files" example in Python:

import os
from marcel.api import *

for file in (ls(os.getcwd(), file=True, recursive=True) |
             select(lambda f: now() - f.mtime < days(1))):
    print(file)

ls(os.getcwd(), file=True, recursive=True) invokes the ls operator as a function, passing in the current directory, requesting only files (file=True), and recursive exploration of the directory (recursive=True). The resulting Files are passed to the select function, which checks for Files modified in the past day. The shell part of the command (ls ... | select ...) yields a Python iterator, so that the resulting Files can be accessed using a for loop.

  • github
  • Twitter
  • email