Workflow automation tool
Project description
wa is a prototype and development is not planned. This version is likely to contain errors. It is recommended to use Python 3.x, work in Python 2 not tested.
wa (workflow automation) — simple cross-platform tool created to automate routine tasks in the development process. For example, it can be used to quickly create a skeleton project from a previously created template or perform complex tasks in a single command.
The goal of wa is to allow us to share best practice in software development and simplify the reuse of code in their software projects. The manifest file in YAML format contains the commands and corresponding actions, and preparation of the source code files are stored as templates. The manifest and templates can be distributed along the source code of your project.
Installation
Using pip
pip install wa
Using easy_nstall
easy_install wa
from source code
git clone https://github.com/char16t/wa.git
cd wa
make install
Quick start
wa may be called from console
wa
wa: workflow automation tool
wa takes as command arguments, which are mapped to actions. Describing one command startproject
you can call it as follows:
wa startproject
Commands unlimited nesting are supported. You can also describe the commands python startproject
, startproject cpp
or startproject cpplib
. You can call them so:
wa startproject python
wa startproject cpp
The commands are described in the files .wa
in YAML format. For the examples above it might look like this:
startproject:
python:
- input PROJECTNAME
- mkdir ${PROJECTNAME}
- mkdir ${PROJECTNAME}/tests ${PROJECTNAME}/${PROJECTNAME}
- touch ${PROJECTNAME}/tests/__init__.py
- touch ${PROJECTNAME}/${PROJECTNAME}/__init__.py
cpp:
- input PROJECTNAME
- mkdir ${PROJECTNAME}
- mkdir ${PROJECTNAME}/src ${PROJECTNAME}/tests ${PROJECTNAME}/include
- touch ${PROJECTNAME}/CMakeLists.txt
- touch ${PROJECTNAME}/src/${PROJECTNAME}.cpp
- touch ${PROJECTNAME}/include/${PROJECTNAME}.hpp
cpplib:
- cp /home/user/mypath/templates/cpplib .
The file .wa
can be located in the root of your project and in your home directory. wa will first try to do a search of the requested command in the root of your project, and then, if the command is not found, will return to the file .wa
in your home directory and looks for there. That is, by creating the file .wa
as in the above example in your home directory, you will be able to perform
$ wa startproject python
You are prompted to enter a value for the variable PROJECTNAME
$ wa startproject python
$ PROJECTNAME=_
Let it be helloworld
:
$ wa startproject python
$ PROJECTNAME=helloworld
and deploy the skeleton of a Python project helloworld
in any directory. Please note that in the current directory, perhaps it should also create an empty file .wa
. It will be a signal to wa that it is the root of the project. Now, if you go in a subdirectory of the current directory and attempt to execute an arbitrary command, the search will be done first in that file that is one level higher in the directory tree.
wa does exactly that: search a file in the current directory first, then in the directory above and so on until the root file system. If the file is .wa
was not found, the search will continue in your home directory.
In the file .wa
lying at the root of your project you can override any command (for example, python startproject
from the listings above). That is, you can redistribute it and .wa
-file along with the code of your project and to help other developers, for example, to quickly create the skeleton of the class, formatted according to the standards of the project.
wa also allows you to work with files and directories relative to the root of your project. By specifying a vertical line before the path to the file or directory
newclass:
- input CLASSNAME
- cp |.code_templates/class.cpp |src/${CLASSNAME}.cpp
- cp |.code_templates/header.cpp |include/${CLASSNAME}.hpp
In the execution of the above example copies the file .code_templates/class.cpp
and .code_templates/header.hpp
with the specified name in the directory src
and include
, respectively. The main thing here is that you can be in any directory of your project, but a copy will be made relative to the root project, because it is explicitly specified with a vertical bar |
.
In the example below, a vertical bar at the beginning of the second there are no arguments
newclass:
- input CLASSNAME
- cp |.code_templates/class.cpp ${CLASSNAME}.cpp
- cp |.code_templates/header.cpp ${CLASSNAME}.hpp
When running this example will copy all the files with the specified names in the current directory. For example, if you are in the directory my_great_cpp_app/legacy
, the files will be copied into it, and if you’re in my_great_cpp_app/legacy/tests
on it.
A vertical bar at the beginning of the paths to files and folders can be used in any commands.
The available commands (API)
You can use the following commands. For each command an example of using.
set
set <variable> <value>
sets the value for the variable. After that, in any commands, you can use a variable like ${variable}
. The variable names are defined case-sensitive.
create_file_and_directory:
- set PREFIX mysuperpupuer
- touch ${PREFIX}_file.txt
- mkdir ${PREFIX}_dir
input
input <variable>
requests for input from the user variable
startproject:
- input PROJECTNAME
- mkdir ${PROJECTNAME}
- touch ${PROJECTNAME}/README.txt
cd
cd <path>
goes to the specified path.
startproject:
- input PROJECTNAME
- mkdir ${PROJECTNAME}
- cd ${PROJECTNAME}
- touch README.txt
mkdir
mkdir <directory name> [<directory name> [<directory name>]]
creates dirs with the specified names.
mkdirs:
- mkdir one two three/four
touch
touch <file name> [<file name> [<file name>]]
creates files with the specified names
touchs:
- touch one two three/four
rm
rm <file or directory name> [<file or directory name> [<file or directory name>]]
removes files and folders with the specified names.
clean:
- rm build
- rm dist
cp
cp <source> <target>>
copies from source to target.
license:
- input LICENSE_NAME
- cp /home/user/templates/${LICENSE_NAME}.template |LICENSE
cptpl
cptpl <source> <target>
copies from source to target with replacement [[variable]]
on the value of the variable in file names and folders and <<<variable>>>
the value of the variable in the contents of the files.
license:
- input PROJECT_NAME PROJECT_DESCRIPTION PROJECT_LICENSE
- cptpl /home/user/templates/cpp_lib |.
The first argument specifies the folder that contains the template, and the second argument the path where the template will be copied. For example, for the Python project template might look like this: create directory /home/user/templates/python
with the following content
[[PROJECT_NAME]]
__init__.py
[[PRPJECT_NAME]].py
tests
__init__.py
Insert to file [[PRPJECT_NAME]].py
this content:
# This file is a part of <<<PROJECT_NAME>>>
# Licensed under MIT. See LICENSE file for details
# (c) 2015 <<<AUTHOR_NAME>>> <<<<AUTHOR_EMAIL>>>>
def main():
pass
if __name__ == "__main__":
main()
Now when you call wa will be prompted to enter the values of the variables, and then the template will be copied. It looks like .wa
-file
pyscaffold:
- cptpl /home/user/templates/python |.
Please note that in the example above are not required to ask the user to input the required variables. The prompt will happen automatically as soon as encountered unknown variable.
Now you need to run in console
$ wa pyscaffold
$ PROJECT_NAME=helloworld
$ PROJECT_AUTHOR=Foo Bar
$ AUTHOR_EMAIL=foo@bar.com
As a result, it will create the following directory structure
helloworld
__init__.py
helloworld.py
tests
__init__.py
And the file helloworld/helloworld.py
will have the following content
# This file is a part of helloworld
# Licensed under MIT. See LICENSE file for details
# (c) 2015 Foo Bar <foo@bar.com>
def main():
pass
if __name__ == "__main__":
main()
cptpljinja2
cptpljinja2 <source> <destination>>
copy from source to target with replacement [[variable]]
on the value of the variable in file names and folders and compiles content from Jinja2 templates that are in the source files.
license:
- input PROJECT_NAME PROJECT_DESCRIPTION PROJECT_LICENSE
- cptpljinja2 /home/user/templates/cpp_lib |.
mv
mv <source> <destination>
moves the files and folders from source to destination..
to_legacy:
- input CLASS
- mv |src/${CLASS}.cpp |legacy/src/${CLASS}.cpp
- mv |include/${CLASS}.hpp |legacy/include/${CLASS}.hpp
echo
echo <message>
displays a message on the screen.
copy_large_file:
- cp /home/12Gb.raw |.
- echo Ok, copied
exec
exec <command>
executes the command on the command line of the operating system.
test:
- cd |.
- exec make test
py
py <file name> <function>
execute function from file in Python interpreter.
test:
- cd |.
- py runtests.py main
Issues
About any errors, problems, any questions or with any suggestions you can write to v.manenkov (at) gmail.com or create a issue in Github Issues https://github.com/char16t/wa/issues
License
Source code licensed under MIT. Текст лицензии находится в файле LICENSE. The license text is in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.