Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

poor man's IDE

by pc88mxer (Vicar)
on Jun 29, 2008 at 23:15 UTC ( [id://694660]=CUFP: print w/replies, xml ) Need Help??

Here's a simple idea that others might find useful. Lately I've been playing around with Google Appengine. Like Catalyst and Ruby on Rails, you create directory for your project, and you often need to refer to this directory to access project specific scripts and files. The problem is that I often don't use a GUI editor for development, and so I navigate around my project files using cd and ls. Consequently, when it comes time to run a project-related command, my current working directory could be anywhere in my project tree.

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"; }

The way it works is this: after editing and viewing files I decide I want to upload the project to AppEngine. The command for that is:
appcfg.py update project_root
Instead of having to remember what my project root is, I can just type:
appeng update
and 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:

cd "$(appeng appdir)"
Of course, this can be made a shell alias or function.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://694660]
Approved by GrandFather
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-24 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found