Automating Tasks with Aap
Many people use a Makefile and shell scripts to automate tasks where a change to a file requires an action to be taken. You edit a file and then invoke make in the hope that all actions necessary to effect the changes are done. Often you need to tweak the Makefile to get it right and end up using touch to work around a missing dependency. As a result, when other people look at your carefully tuned Makefile, they have a hard time understanding how it works.
These tasks can be done more easily and reliably with Aap than with make. For example, Aap has built-in Internet support. Downloading and uploading is taken care of without the need to specify the commands or to keep timestamp files. Reliability is achieved by figuring out dependencies automatically and using signatures instead of timestamps. With Aap it is simpler to specify the work you want done, and you make fewer mistakes. You still can fall back on using shell commands where you want them. This article presents two examples of Aap in action, maintaining a Web site and building a program. Aap can do much more, of course, but these subjects should be sufficient to get you started.
To use Aap you need Python version 1.5 or later. In the unlikely event that you do not have Python on your system, download it from Python.org, or install it from your Linux distribution CD or update system.
Installing Aap can be done in four simple steps. Start by downloading the latest Aap zip archive (see the on-line Resources section). Then, unpack the archive in a temporary directory (unzip aap-1.053.zip). If you are root, run ./aap install. If you are a normal user, install the archive in your home directory with ./aap install PREFIX=$HOME. For more information about downloading and installing Aap, see Resources. Aap is distributed as open-source software under the GNU GPL.
With the current Aap software in place, let's look at using it in a basic example task. You have designed a simple Web site with HTML files and images. The files are on your local computer, and you need to upload them to the Web server. Listing 1 shows the Aap script, called a recipe, that does this.
Listing 1. Recipe for Uploading Files to a Web Server
# The list of files to be uploaded.
Files = index.html
info.html
download.html
images/*.png
# The publish attribute tells where to upload to.
:attr {publish = scp://my.server.net/html/%file%}
$Files
# When executed without a target: publish the files.
all : publish
Store the recipe under the name main.aap. This file is what Makefile is to make—the default file to be executed. Running aap without arguments executes the main.aap recipe in the current directory.
Comments in an Aap recipe start with # and continue until the end of the line, as in a Makefile or shell script. The first effective line in the recipe is an assignment; the list of files to be uploaded is assigned to the Files variable. There are no back slashes nor punctuation to mark the end of the assignment. Aap recognizes command continuation by the amount of indentation used. This may appear strange at first, but you quickly get used to it. This method avoids the usual mistakes with punctuation and enforces a layout that is easy to read. Aap allows you to use either tabs or spaces to indent lines.
The :attr line is an Aap command. All Aap commands start with a colon to make them easy to recognize. This command adds the publish attribute to its arguments. The publish attribute tells Aap where to upload the files when they are published. The method used here is scp://, secure copy. Other supported methods are rsync:// and ftp://. The last argument of :attr is $Files, the value of the Files variable. The attribute is attached to each item in $Files.
When you run Aap without an argument, it updates the target all. The final line specifies that the default target all depends on publish. This is a special target, which tells Aap to upload all items that have a publish attribute.
You now can edit the HTML files, add pictures and view them locally. Once you are satisfied, execute aap. Aap figures out which files have changed and uploads them. Signatures (checksums) are used; thus, if you restore an old version of a file it still works properly. If you were using make, you would have to touch the restored file to update its timestamp.
If you want to try this example, but you don't have a server to upload to, you can use the publish attribute file:/tmp/html/%file%. With it, Aap creates the /tmp/html directory, if necessary.
A word of warning: Aap does not delete files on the server no longer in use. Then again, neither does make. You have to delete these files manually. Hopefully, automatic deletion will be added to Aap soon.
Trending Topics
| Sleep Fast, Sleep Hard with the Pzizz Android App | Jan 10, 2018 |
| Analyze Song Lyrics with a Shell Script, Part II | Jan 09, 2018 |
| Linux Filesystem Events with inotify | Jan 08, 2018 |
| What I See for LJ 2.0: in a Word, Community | Jan 08, 2018 |
| Emacs for Science | Jan 07, 2018 |
| Let's talk advertising | Jan 06, 2018 |
- Sleep Fast, Sleep Hard with the Pzizz Android App
- Understanding Firewalld in Multi-Zone Configurations
- The Weather Outside Is Frightful (Or Is It?)
- SNMP
- Linux Journal February 2017
- From vs. to + for Microsoft and Linux
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Buddy Platform Limited's Parse on Buddy Service
- A Switch for Your RPi
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
Geek Guides
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.
Get the Guide


Comments
Website maintenance
Hi Bram
Thank you for your great tutorials.
I Use a lot of it myself and you have been a great help to turn to whenever i am stuck on a project.
Please keep up the good job.
Jeff
Founder of
Install Software