A way I've found to mitigate this is to mark the project root by creating a special file there - like .appengine. Then I write a script that can be used with all AppEngine projects that goes something like this:
#!/usr/bin/perl use strict; use warnings; use Cwd; use File::Basename qw(dirname); sub app_directory { my $updir = getcwd; my $dir = ''; while ($updir ne $dir) { $dir = $updir; if (-f "$dir/.appengine") { return "$dir/app"; } $updir = dirname($dir); } die "not in an appengine workspace\n"; } sub sys { print "Executing: @_\n"; my $st = system {$_[0]} @_; if ($st == -1) { die "Exec failed: $!\n"; } } sub appdir { print app_directory(), "\n"; } sub server { my $appdir = app_directory(); sys("dev_appserver.py", "--address=0.0.0.0", $appdir, @_) } sub appcfg { my $appdir = app_directory(); my $cmd = shift; sys("appcfg.py", @_, $cmd, $appdir); } sub help { print <<END; Available appengine commands: help - list available commands appdir - print workspace directory server ... - start server update ... - perform update appcfg ... - invoke appcfg.py END } my $cmd = shift; if ($cmd eq "server") { server(@ARGV); } elsif ($cmd =~ m{\A(update|rollback|update_indexes|vacuum_indexes)\z}) { appcfg($cmd, @ARGV); } elsif ($cmd eq "appdir") { appdir(@ARGV); } elsif ($cmd eq "help") { help(@ARGV); } else { die "unknown command: $cmd -- use 'help' for a list of commands\n"; }
appcfg.py update project_rootInstead of having to remember what my project root is, I can just type:
appeng updateand the appeng script will run the correct command for me.
Another example: using the appdir command you can quickly cd to your project's root with:
Of course, this can be made a shell alias or function.cd "$(appeng appdir)"
This script also serves as a way of defining shortcuts for frequently run commands much like a Makefile. Indeed, I often write a make command for these kinds of scripts that will perform a cd and execute a top-level make.
Also, I've found this approach to be very helpful when working on multiple versions of a project each in their own directory.
I'm sure I'm not the first person to think of this idea, but I've found it very useful, so I thought I'd share it. And I decided to write it in perl.
|
|---|