TaSp project


Contents:

Definition

What is TaSp?

TaSp logoThe TaSp project consists of two simple components to replace tabs with spaces (or vice versa) for a consistent indentation method inside files and also to consistently indent messed up files.





Details

Further information about the project.

Python poweredThe TaSp project is written in Python and platform independent.

Due to the fact, that the project is intended for shell and scripting purposes, it does not come with a graphical user interface.

The name TaSp is an abbreviation of Tabs and Spaces.

When many different people work on the same text, config or code file, the indentation inside often gets messed up because different text editors with different indentation methods (spaces or tabs) were used. Depending on the preferences set up in the text editors, these will represent the tabs differently on the screen.

For example, a user who prefers a tab with the width of eight spaces and which is saved as tab character creates a file. When another user who prefers a tab with the width of four spaces opens that file, the indentation may look messed up to him.

Some people prefer saving tabs as spaces. Instead of saving tabs with the tab character, the tab will be saved with a user-defined amount of spaces (e. g. four spaces for one tab). So, no matter what the preferred tab width is, the indentation looks identical in every text editor.

Every user has his own preferences or specifications what type of indentation to use. To avoid a complete mess, tab and space indentations basically should not get mixed inside a file. Depending on the amount and size of the files, manually adjusting the used indentations sometimes takes quite some time.


Indentation method

Usually, operating systems provide powerful command line tools (e. g. sed on Unix-like systems) that also allow to accelerate such a process, but these often are quite extensive (due to a lot of features) and may require some shell experience.

For example, if you want to use sed (details can be found here) to replace every tab with four spaces inside all files with the file extension cfg that are located in the directory /tmp/foobar and all of its sub-directories, you could either write a simple shell script like this


#!/bin/bash

for cfg_file in $(find /tmp/foobar -type f | grep "\.cfg$"); do
    cat "$cfg_file" | sed -e "s/\t/    /g" > /tmp/sed_replace.tmp
    mv -f /tmp/sed_replace.tmp "$cfg_file"
done


or convert that script into a single command line:


$ find /tmp/foobar -type f -regex ".*\.cfg$" -exec sed -i "s/\t/    /g" {} +

The TaSp project provides the replace component which is a command line tool indeed, but its main purpose is to get a consistent indentation method inside files, so it only requires a few simple command-line arguments for that purpose:


$ ./tasp-replace.py -d /tmp/foobar -r -f cfg --overwrite -m spaces -s 4

Consistent indentation

After getting a consistent indentation method (as described inside the paragraph above), the files may still be messed up like this sample config file:


server myserver {
   ip_address   
192.168.1.1# IP address
  name   myserver.foo.bar;   # host name
      type    foobar# server type
     description    foobar server# server description
}


The TaSp project also provides the indent component which also requires a few simple command-line arguments, only.

For example, to indent the messed up lines with four leading spaces and the items per line using a padding of twenty spaces, the command would look like this


$ ./tasp-indent.py -d /tmp/foobar -r -f cfg --overwrite -s 4 -p 20

and change the indentation as follows:


server myserver {
    ip_address         
192.168.1.1;        # IP address
    name                myserver.foo.bar;   # host name
    type                foobar;             # server type
    description         foobar server;      # server description
}



Components

What the project consists of and what each component is for.

TaSp Indent

The indent component consistently indents messed up files. Details can be found above.


TaSp Replace

The replace component replaces tabs with spaces (or vice versa) for a consistent indentation method inside files. For details see above.



Requirements

Stuff that is required to get TaSp running.

Software requirements:

  • Python framework (either of them, further information can be found here)
    • Python 2.x (version 2.7 or higher is recommended, may also work with earlier versions)
    • Python 3.x (version 3.2 or higher is recommended, may also work with earlier versions)


Usage

How to use TaSp.

The following usage example shows how to execute the Python script on the shell of a Unix-like system.

If you do not know, how to run Python scripts on your operating system, you may click here.

The project also comes with some help files which contain fundamental documentation as well as usage examples for each component of the project.

Usually, each script requires command-line arguments to operate. So, to get an overview of all arguments available, simply run the script with the --help argument. For example:


$ ./tasp-indent.py --help
usage: tasp-indent.py -d DIRECTORY -f FILE_EXT -p PADDING -s SPACES
                      [--confirm] [-h] [-l] [--overwrite] [-r] [--verbose]
                      [--version]

Consistently indent messed up files (especially config files) using a user-
defined amount of spaces.

required arguments:
  -d DIRECTORY, --directory DIRECTORY
                        directory that contains the files to process
  -f FILE_EXT, --file-extension FILE_EXT
                        file extension of the files to process
  -p PADDING, --padding PADDING
                        padding (in spaces) used to indent each item inside a
                        line
  -s SPACES, --spaces SPACES
                        amount of leading spaces for each indented line

optional arguments:
  --confirm             skip the confirmation prompt and instantly process the
                        data (in case the '--overwrite' argument was given)
  -h, --help            print this help message and exit
  -l, --left-justify    left-justify the line if it only consists of a single
                        character
  --overwrite           overwrite the input file with the processed data
                        (instead of creating an output file with the same name
                        and the additional suffix '.tasp')
  -r, --recursive       process the given directory recursively
  --verbose             use verbose mode (print details while processing data)
  --version             print the version number and exit

Further information and usage examples can be found inside the documentation
file for this script.
$


Current state

What is the state of development?

Dead-end sign The development of the TaSp project has been discontinued so far.

Initially developed for fixing messed up config files of a monitoring software, TaSp has lost its importance after that software has been replaced by another one without a messed up configuration.

After that, there was no more reason to continue the development.



Download

Download the project.

Below you can download the latest version of the project for different Python frameworks. Further information about these frameworks can be found here.


Version:


2.0.9



TaSp logo

Release date:


2015-04-04




File size:


< 30 KB




Current state:

Discontinued
Discontinued
Details












License:



MIT License


Framework:


Python 2.x
Python 3.x


Download:


tgz | zip
tgz | zip