If you manage your own Drupal servers, and have shell access, one of your most powerful tools for deployment are CVS and SVN. Using the CVS deploy module, you can get rid of that tedious Download to computer -> upload via FTP process.
I found a powerful piece of code on the website of Kathleen Murtagh. The code was optimized by drupal user dgtlmoon. By applying a simple condition, and using the code as a function within .bashrc or .bash_profile, you add some needed functionality when managing a Drupal server (or anything else really) using SVN.
Here's the code you need for your .bashrc in case you already know what's going on. It allows you to pass in regular expressions to be applied to the svn status function. If you supply a second argument, it's used as the SVN option for each of the filtered files. Cool Stuff!
svngrep()
{
# Modified from
# http://ceardach.com/
if test -z "$2"; then
svn status | egrep "${1}" | awk '{print $2}'
else
svn ${2} `svn status | egrep "${1}" | awk '{print $2}'`
fi
}


This is excellent. I'm please to see that my post inspired such a handy script as this!
I am getting a strange error when I try to run the command with that second action piece, to remove some files.
svn: invalid option character: f
Any ideas?
I've not seen that error myself. However, one thing I have run across is that you have to properly escape your grep syntax.
Because the function is using egrep (extended regular expressions), you need to be aware of special characters.
For example, if you want to filter based on files indicated with the ? then you need to use \? because normally the ? is a special character in regex.
Also, if the second portion of the command contains spaces then you'll need to quote it too.
Here is an example.
svngrep "\?.*.txt" "add -switch"Where -switch is an option for the svn add command
I finally discovered that the issue is a file called "-f". I deleted it manually, but am failing at removing it from the SVN. That is where the illegal character option came in.
I couldn't find any useful scripts, probably because I didn't come up with the term "svn filtering". That's why I wrote my own script that does the same thing, but completely automated. You won't have to pass any secondary commands anymore. I think that in most use cases, that's desired. The script you use allows for more power of course :)
You can find it at http://wimleers.com/blog/syncvsvn-synchronize-cvs-working-copy-with-svn-....
I will certainly add your script to my personal work flow. There will, for sure, be cases where I want to use one or the other. I've also have some other functions (in my bashrc) which are similar to those listed in the comments on your article above. Here they are.
# These are functions in my .bashrc file
# Get a new drupal module
d6mod()
{
MODULE="${1}"; cd $DRUPALROOT/sites/all/modules/; \
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d ./$MODULE contributions/modules/$MODULE
cd $MODULE
drevs $MODULE.module
}
# Get a new drupal theme
d6theme()
{
THEME="${1}"; cd $DRUPALROOT/sites/all/themes/; \
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d ./$THEME contributions/themes/$THEME
cd $THEME
drevs page.tpl.php
}
# List the revisions of the supplied file
drevs()
{
cvs log "${1}" | egrep 'DRUPAL-.*:' | sort
}
# Do a cvs update using the specified revision
dup()
{
cvs up -dP -r "${1}"
}
You can see that I reference some previously declared env variables pointing to the location of my drupal root and I also simply grab the specified branch (which hopefully the contributor is using) and do a cvs log using my drevs function. This allows me to have a list, in the terminal, of revisions I can choose from. Issue a simple dup and I've got the revision I want.
Suggestions and improvements are ALWAYS welcome!
I'm curious what you have set as $DRUPALROOT in your shell script. How do you manage multiple installs of Drupal? Wouldn't it be easier to handle multiple instances by removing the $DRUPALROOT directory from the script and cd'ing to the modules directory relative to the path you are at. The only issue is you would have to be in the site root of your drupal install to execute these commands, but that is inherent with drush as well.
How do you handle multiple Drupal installs?
I only have one install of Drupal 6 on my local install. I'm not doing anything in Drupal 5 anymore.
There are a couple of ways you could deal with multiple local installs. You could pass in arguments into the function to specify the drupal root folder if you have multiple installs. For example d5 vs d6. Where your profile would look like this
export d6='/path/to/drupal-6/root/sites/all/modules'export d5='/path/to/drupal-5/root/sites/all/modules'
You could also make separate functions for the various installs - which I've done before.
And, of course, as you mentioned you could modify the function to simply work within the local folder you had cd'd into.
With a bit of conditional logic, you could test to make sure you're actually in the modules folder.
Re: Drush, I've used it but with multisites, you have to specify this on the command line and that is too much typing for me. I typically don't run anything out of default so Drush, while powerful, it not as simple as the functions I use when the path is known. I do use Drush for other things though.
Here's an updated revisions function which pulls the revisions of a module from the CVS log function.
Remember, if this function is called within another function, such as when downloading a module. There's no guarantee the file whatever.module exists. This means you would need to run this function manually on whatever you want the CVS log from. (e.g drevs README.txt or some other file.)
# A function which pulls the cvs log from a specified file and pulls out only REVISION tags (and sorts them)drevs()
{
cvs log "${1}" | egrep 'DRUPAL-.*:' | sort -t - -k 2n -k 3n -k 4n -k 5n
}
The updated code will now sort the results of the grep on the log in a proper numeric fashion. Much easier for finding the revision you want to update to.
Thanks for the link. I like this video, can you share more video again? classifieds |ads|orange county restaurants