Skip to main content

Name

jjcli - python module for command-line filter

Synopsis

as ascript:

jjcli skel     ## a initial filter skeleton
jjcli          ## manual

as a module:

from jjcli import *       ## re.* functions also imported
c=clfilter(opt="do:")     ## options in c.opt  (...if "-d" in c.opt:)
                          ##    autostrip         (def=True)
                          ##    inplace           (def=False) 
                          ##    fs (for csvrow()) (def=",")

for line in c.input():...    ## process one rstriped line at the time
for txt in c.text():...      ## process one striped text at the time
   ## process txt            ##   (end of line spaces and \r also removed)
for par in c.paragraph():... ## process one striped paragraph at the time
for tup in c.csvrow():...    ## process one csv row at the time
for tup in c.tsvrow():...    ## process one tsv row at the time

c.lineno()                ## line number
c.filelineno()
c.parno()                 ## paragraph number
c.fileparno()
c.filename()              ## filename or "<stdin>"
c.nextfile()
c.isfirstline()
c.args  c.opt             ## command line arguments and options (after clfilter())

Description

jjcli is a opinioned Python module that tries to simplify the creation of unix filters. It is based on:

  • getopt (for command line options and args)
  • fileinput (for [files/stdin] arguments)
  • re (regular expressions should be native)
  • glob (glob.glob should be native)
  • csv (for csv and tsv inputs)
  • urllib.request (to deal with input argumens that are url)
  • subprocess

Regular expressions

We want to have all re.* functions available (as if they were native functions).

In order to enable re flags, use: re.I re.X re.S

Subprocesses (qx, qxlines, qxsystem)

a=qx( "ls" )
for x in qxlines("find | grep '\.jpg$'"): 
  ...
qxsystem("vim myfile")

Execute command return its stdout

qx(*x)      →  returns    subprocess.getoutput(x)

Execute command return its stdout lines

qxlines(*x) →  returns    subprocess.getoutput(x).splitlines()

Execute command -- system

qxsystem(*x) →  calls     subprocess.call(x,shell=True)

STDERR - warn, die

warn(*args)  → print to stderr
die(*args)   → warn and exit 1

Other functions

slurpurlutf8(self,f)

filename    = lambda s : F.filename()      # inherited from fileinput
lineno      = lambda s : F.lineno()
filelineno  = lambda s : F.filelineno()
parno       = lambda s : s.parno_          # paragraph number
fileparno   = lambda s : s.fileparno_
nextfile    = lambda s : F.nextfile()
isfirstline = lambda s : F.isfirstline()
isfirstpar  = lambda s : s.fileparno == 1
close       = lambda s : F.close()

Metadata

Release files for jjcli 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jjcli 0.1.20
File Size Uploaded
jjcli-0.1.20.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jjcli 0.1.20
File Interpreter ABI Platform
jjcli-0.1.20-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 8.0 kB

Release files / jjcli-0.1.20.tar.gz

Download URL jjcli-0.1.20.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e3b9b7a331241cd99c8e1e8ea12bfa2a6c7b96ed7ba4b6fd387d7d81b7577f4a
BLAKE2b-256 checksum
How to use checksums
207db62220a44ebcb395796f0c26f0fd79b9f70c50af0b26cb9a58fb3060708c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release files / jjcli-0.1.20-py2.py3-none-any.whl

Download URL jjcli-0.1.20-py2.py3-none-any.whl
Size 4.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8081062b035c82154ca51a422bcade5954537179401f39b9afbb0a7cd95361c2
BLAKE2b-256 checksum
How to use checksums
90129b60fd97f0474dadebe988b12f9005c1adbf62cc25ea0b7344fc5a5d34db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.26.0

Release history Release notifications | RSS feed

0.1.29

2 release files

0.1.28

2 release files

This release

0.1.20 This release

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.8

2 release files

0.1.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page