Ode to wgd and the command line

Posted on July 14th, 2009 in Perl, WebGUI by Patrick

Doug just posted an ode to the Linux command line over at the Plain Black staff blog.

I’ve been getting a lot of joy out of the command line today too thanks to Graham’s ridiculously useful WGDev. One wgd command that I only started using in earnest today is the ls command. In its most basic form, it lets you print out a list of assets on your site:


$ wgd ls /home

getting_started
your_next_step
the_latest_news
tell_a_friend
documentation
site_map

I added a bunch of extensions to ls today, the first one being a -r option that tells ls to recursively list assets. Given that this prints to STDOUT, you can pipe this into any other command line tool to manipulate the output. For example, to list all assets that have the word “you” in their menu title:


$ wgd ls /root -f "%menuTitle%" -r | grep -i you
Profile Account Layout
Inbox Account Layout
Friends Layout Template
Account Layout
Shop Account Layout
Contributions Layout
Default Account Layout
Layout
Your Next Step

(the -f “%menuTitle%” option above tells the command to output only the menuTitle property of each asset).

Under the hood ls is calling asset->getLineage(), so I exposed a few of the getLineage API options to ls.

For example, this is one way of getting a sorted list of Survey templates on your site:


$ wgd ls root -r --includeOnlyClass WebGUI::Asset::Template -f "%url% %namespace%" | perl -ane 'print "$F[0] ($F[1])\n" if $F[1] =~ m/survey/i' | sort
root/import/expireincompletesurveyresponses/expireincompletesurveyresponses (ExpireIncompleteSurveyResponses)
root/import/survey/default-answer-edit (Survey/Edit)
root/import/survey/default-feedback (Survey/Feedback)
root/import/survey/default-gradebook-report (Survey/Gradebook)
root/import/survey/default-overview-report (Survey/Overview)
root/import/survey/default-question-edit (Survey/Edit)
root/import/survey/default-questions (Survey/Take)
root/import/survey/default-section-edit (Survey/Edit)
root/import/survey/default-survey-edit (Survey/Edit)
root/import/survey/default-survey-summary (Survey/Summary)
root/import/survey/default-survey (Survey)
root/import/survey/default-survey-take (Survey/Take)
root/import/survey/default-test-results (Survey/TestResults)

While I was writing this post, Andy asked me to provide him with a list of all Carousel wobjects on a site we’re working on. That’s as easy as:


$ wgd ls -r root --includeOnlyClass WebGUI::Asset::Wobject::Carousel

The most useful option I added to ls is the –filter smartmatch filter option. This option filters the results using an asset property of your choosing. Format looks like “%url% ~~ smartmatch”, where “url” is the field to filter against, and “smartmatch” is either a Perl regular expression such as “/(?i:partial_match)/” or a string such as “my_exact_match”.

For example, the following command lists all templates that include absolute urls. We generate the output to an html file so that someone can easily open all the links and manually review/remove the absolute urls:


$ wgd ls -r /root --filter "%template% ~~ /http:///" --includeOnlyClass WebGUI::Asset::Template --format "<a href=http://dev.localhost.localdomain/%url%?func=edit>%url%</a><br>" > links.html

links.html then contains:

<a href=http://dev.localhost.localdomain/style_01?func=edit>style_01</a><br>
<a href=http://dev.localhost.localdomain/style_02?func=edit>style_02</a><br>
<a href=http://dev.localhost.localdomain/style_03?func=edit>style_03</a><br>

...

One type of command that I can see myself using a lot in the future is the following, which displays all assets that are viewable to a specific group (in this case the “Turn Admin On” group, which has an id of “12″):


$ wgd ls -r root --format "%groupIdView% %url%" --filter "%groupIdView% ~~ 12"
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki

Alternatively, you can use a variation of the above to list all assets that are NOT viewable to a certain group (or groups). This is great for finding assets that have accidentally been set to say, Admins, when you want them viewable by Registered Users. For example, the following command lists assets that are not viewable to the default “Visitors”, “Everyone”, or “Registered Users” groups:


$ wgd ls -r root --format "%groupIdView% %url%" | perl -ane 'print "$F[0] $F[1]\n" if !grep {$F[0] eq $_} qw(1 2 7)'
12 root/import/newsletter
12 root/import/projectmanager/resource
12 root/import/wiki

All of these commands take in the order of 1 second to run, which is a lot less time consuming than manually reviewing your site asset-by-asset. And if you incorporate them into your test suite, you can re-verify their output against your site policy/expectations whenever you like.

5 Responses to 'Ode to wgd and the command line'

Subscribe to comments with RSS or TrackBack to 'Ode to wgd and the command line'.

  1. Ehab said,

    on July 14th, 2009 at 9:32 pm

    Amazing stuff, can you point me to any documentation on how to install wgd

  2. Patrick said,

    on July 14th, 2009 at 9:54 pm

    @Ehab: I’m not sure if there is much in the way of structured releases yet, (or install docs) so I’m just building direct from git.

    Clone from Graham’s repo:

    $ git clone git://github.com/haarg/wgdev.git

    Or mine if you want the ‘ls’ changes that I pushed up today:
    $ git clone git://github.com/pdonelan/wgdev.git

    And then cd into the newly created dir and run:
    perl Build.PL && ./Build test && ./Build install

    Or just:
    cpan .

    One of the nice things is that you can run wgd on a completely different perl than the one your modperl is using. For instance, I use my Ubuntu system perl for wgd, which means I don’t have to source /data/wre/sbin/setenvironment.sh anymore. It also means that you can e.g. run wgd in a threaded perl (which the wre perl is not) – which is necessary if you want to use the Padre WebGUI/wgd plugin.

  3. Graham said,

    on July 15th, 2009 at 1:30 am

    There isn’t much for install documentation as it works as a standard CPAN module. I am doing proper releases through the WebGUI bazaar: http://www.webgui.org/bazaar/wgdev The main thing I need to finish for 0.4.0 is finishing the documentation improvements I have in progress.

    I’ll be pulling Patrick’s changes into my repository soon as well.

  4. Graham said,

    on July 15th, 2009 at 8:05 am

    I should also mention that feature requests, bugs, or other things you think should be changed can go on the GitHub Issues page: http://github.com/haarg/wgdev/issues


  5. on July 30th, 2009 at 7:07 pm

    [...] Graham on Ode to wgd and the command lineGraham on Ode to wgd and the command linePatrick on Ode to wgd and the command lineEhab on Ode to [...]

Post a comment