Skip to main content

Python library for common shell-like script tasks.

Project description

License Build Status

Introduction

This project provides a Python 2.7/3.x library for common tasks especially when writing shell-like scripts. Some of the functionality overlaps with the standard library but the API is slightly modified.

The goal of this project is to leverage the straightforward, clean syntax of Python while avoiding some of the boilerplate code that might be necessary when using the standard library.

Status

Currently, this project is in the development release stage. While this project is suitable for use, please note that there may be incompatibilities in new releases.

Release notes are maintained in the project changelog.

Requirements

Auxly should run on any Python 2.7/3.x interpreter without additional dependencies.

Installation

Auxly can be installed with pip using the following command: pip install auxly

Additionally, Auxly can be installed from source by running: python setup.py install

Usage

Auxly provides various convenience functions for common tasks. Functions that overlap with the standard library are designed to do what you would reasonably expect (POLA) and, when necessary, fail without throwing exceptions.

Auxly provides the following modules:

The following are basic examples of Auxly (all examples can be found here):

Refer to the unit tests here for additional examples.

Top Level

Start by importing Auxly into your Python script:

import auxly

Auxly will attempt to open files and URLs using the default application:

auxly.open("myfile.txt")
auxly.open("https://www.github.com/")

Auxly can tell you if the script is running as an admin:

auxly.isadmin()

Also in the top level is the auxly.throw() convenience function that allows exceptions to be thrown if desired.

File System

The auxly.filesys module provides various convenience functions for working with the file system.

Start by importing the file system module into your Python script:

import auxly.filesys as fs

Checking or changing the current working directory (CWD) is easy:

print(fs.cwd())  # Get the CWD.
fs.cwd("foo")  # Set the CWD to `foo`.
with fs.Cwd(fs.homedir()):  # Temporarily set CWD.
    pass  # do stuff here...

Copying or moving files is a snap:

fs.copy("foo.txt", fs.homedir())  # Simple file move.
fs.move("bar", fs.homedir())  # Entire directory copied.

Note that copy/move functions return a boolean. Miss your exceptions? Try the following:

fs.copy("foo.txt", "bar") or auxly.throw()  # Throws/raises exception on failure.

Check if a file or directory is empty:

fs.isempty("foo.txt")  # Works on files...
fs.isempty("bar")  # ...or directories!

Need to make some directories:

fs.makedirs("bar/baz")

Delete files or directories:

fs.delete("bar")  # Returns true if successful.

There are File and Path objects too:

f = File("foo.txt")
f.write("hello")
f.append(" world")
f.read()  # "hello world"

p = File.path  # Path object
p.isfile()  # True
p.isdir()  # False
p.isempty()  # False

Shell

The auxly.shell module provides various convenience functions for working with the system shell.

Start by importing the shell module into your Python script:

import auxly.shell as sh

Calling command line utilities is easy:

sh.call("ls")

Not sure if a utility is available on the shell? Try the following:

sh.has("ls")
# True

Call a utility while hiding the output:

sh.silent("ls")

Need to iterate over the stdout of a command? Just use:

for line in sh.iterout("cat myfile.txt"):
    print(line)

Or get the stdout as a string:

sh.strout("ls")

Stringy

The auxly.stringy module provides various convenience functions for working with strings.

Start by importing the stringy module into your Python script:

import auxly.stringy as stringy

Substituting within a string is easy:

stringy.subat("bit", 2, "n")
# bin

Need a random string? Try this:

stringy.randomize()
# bnmzwx

Listy

The auxly.listy module provides various convenience functions for working with lists.

Start by importing the listy module into your Python script:

import auxly.listy as listy

Need to split a list into chunks? Not a problem:

list(chunk([1,2,3,4,5,6,7,8], 3))
# [[1, 2, 3], [4, 5, 6], [7, 8]]

Need to smooth a chunky list? Worry not:

list(smooth([1,[2,[3,[4]]]]))
# [1, 2, 3, 4]

Documentation

The full documentation for this project can be found here on Read the Docs.

Similar

The following projects are similar and may be worth checking out:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auxly-0.5.3.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file auxly-0.5.3.tar.gz.

File metadata

  • Download URL: auxly-0.5.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for auxly-0.5.3.tar.gz
Algorithm Hash digest
SHA256 ebefd50060790cb24058fb9a23d2e7845e9e0be58a32b450042413e282c03c4b
MD5 f0cc70c6ee7d3fb4499ea8b4811aa0fb
BLAKE2b-256 66349a4ca8717b4719e77632002bca422de4fe8e279c184666b41d5fd4945a6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page