(Yet another) Python debugging question

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

(Yet another) Python debugging question Mon Jul 04, 2016 10:13 am • by Greybeard
Greetings,

After hearing this app mentioned on numerous podcasts over the years, I decided to download a demo and try to find ways to use it. So seeing several posts around the web on using it to automatically upload files to Amazon S3, I thought I'd try that. I modified (for Python3/boto3) a few of the scripts already out there, and tested it from the CLI. All works as expected.

Then I created a ruleset in Hazel. Since I couldn't figure out how to group triggers, e.g. (this or this or this) AND this, I am using a match rule to match a word-date combo, and an extension of 'pdf'. The matching seems to work, but I can get the script to run (successfully).

Initially I wrote and tested everything in a virtualenv, e.g. Shell = /Users/greybeard/.virtualenvs/hazel/bin/python3, but when that continued to fail, I installed the required modules in the system Python repo and reconfigured the 'shell' to use the default Python3, i.e. /usr/local/bin/python3. That still failed.

After some searching, I found a post on here showing how to enable debug, and another which indicated it might help to include print() statements in the code to track progress. All of which I've done. So the questions:

1) Did Hazel 4 modify the way it interacts with scripts, i.e. should previously posted examples still work?
2) Does it still pass in the path+filename and content type via ARGV?
3) Did H4 modify the way it handles output from a script, i.e. should my print() statements still show up in the log?
4) Is there a way to get it to execute a script from disk, rather than embedded?

Here is the output of the debug log:
Code: Select all
2016-07-04 09:51:29.466 hazelworker[34578] Amazon-20160615.pdf: Rule Upload Bills to Amazon S3 matched.
2016-07-04 09:51:29.957 hazelworker[34578] [Error] Shell script failed: Error processing shell script on file /Users/swschulz/Downloads/Amazon-20160615.pdf.
2016-07-04 09:51:32.007 hazelworker[34578] Amazon-20160615.pdf: Rule Upload Bills to Amazon S3 matched.
2016-07-04 09:51:32.269 hazelworker[34578] [Error] Shell script failed: Error processing shell script on file /Users/swschulz/Downloads/Amazon-20160615.pdf.


Does this mean the file can't even be compiled since even the introductory print() statements do not display? Is there an extra-verbose option?

I also get these when I move the file back out of Downloads, but these I expect:
Code: Select all
2016-07-04 09:51:34.380 hazelworker[34578] DEBUG: Skipped /Users/swschulz/Downloads/Amazon-20160615.pdf. File/folder not part of change set/file event.
        path = "/Users/swschulz/Downloads/Amazon-20160615.pdf";
2016-07-04 09:54:48.729 HazelHelper[70375] DEBUG: Error resolving symlinks for path /Users/swschulz/Downloads/Amazon-20160615.pdf:, No such file or directory
    path = "<ComNoodlesoft_NoodlePathSet: 0x7fd2f871dc30>\n  /Users/swschulz/Downloads/Amazon-20160615.pdf : 0\n";


I can post or link to the script if that would be of any benefit.

Thanks for any assistance!
Greybeard
 
Posts: 2
Joined: Mon Jul 04, 2016 9:59 am

Re: (Yet another) Python debugging question Tue Jul 05, 2016 10:37 am • by Mr_Noodle
First off, to do mixed AND/ORs, hold down option while clicking the + button to create new conditions.

As for your script, you need to turn on debug mode (https://www.noodlesoft.com/kb/hazel-debug-mode/) to see the output of the script itself.

I don't believe anything has changed in Hazel 4 in terms of running scripts. Search the help but in short, Hazel just sends in the path and nothing else. And yes, you can have Hazel execute an external script. Just select it in the pop-up.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: (Yet another) Python debugging question Wed Jul 06, 2016 12:26 pm • by Greybeard
Mr_Noodle wrote:First off, to do mixed AND/ORs, hold down option while clicking the + button to create new conditions.


Thank you, hadn't seen that yet.

Mr_Noodle wrote:As for your script, you need to turn on debug mode (https://www.noodlesoft.com/kb/hazel-debug-mode/) to see the output of the script itself.


Yeah, all of this was done with debug mode on, there just wasn't much info available.

Mr_Noodle wrote:I don't believe anything has changed in Hazel 4 in terms of running scripts. Search the help but in short, Hazel just sends in the path and nothing else. And yes, you can have Hazel execute an external script. Just select it in the pop-up.


It came down to the fact that both of the scripts I was basing mine on had a second option "content-type" listed as being passed in on ARGV[2], so I just copied that part. On a hunch, and after reading the notification message for the umpteenth time, I commented out that piece and all began to work. Re-enabled the virtualenv, etc. All is good.

Thank you
Greybeard
 
Posts: 2
Joined: Mon Jul 04, 2016 9:59 am


Return to Support