Getting shovel to work in windows so python methods can be run like individual executables


/ Published in: Python
Save to your folder(s)

I had hear about a method to run a method like an executable, with the arguments being passed in from the commandline. Apparently, Ruby has this with the Rake project. Well, Python has it with [Shovel](http://devblog.seomoz.org/2012/03/shovel-rake-for-python). Only the instructions didn't work for me on windows, so I had to create a batch script to call `shovel` correctly.

So here's my setup. I installed shovel using `easy_install shovel`, which placed it in my python scripts folder (C:\Python27\Scripts, which is in my PATH). I created 'shovel.bat' (see source) in the same folder. So now I can call `shovel` from anywhere and it will call my batch file, passing the parameters into shovel.

For completeness, here is my working directory structure (note the subfolder called shovel):

D:.
│ song log.log
│ Untitled_10.mp3
│ Untitled_11.mp3
│ Untitled_2.mp3
│ Untitled_3.mp3
│ Untitled_4.mp3
│ Untitled_5.mp3
│ Untitled_6.mp3
│ Untitled_7.mp3
│ Untitled_8.mp3
│ Untitled_9.mp3
│
└───shovel
tasks.py

My python script is incomplete but can be run by shovel using `shovel tasks.extractSongInfo "log file name.log"` from the directory above the 'shovel' directory. Here's the script:


from shovel import task

@task
def extractSongInfo(logFile):
"""Given a log file with lines like
"{date} INFO Currently playing - Song: {songName} - Artist: {artist} - Length: {numSeconds}"
return a collection of extracted info."""
opId = "Extracting song info" # operation ID
print opId
print 'Done: ' + opId

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.