Post processing status code troubles with my PP script

Come up with a useful post-processing script? Share it here!
Post Reply
greenythebeast
Newbie
Newbie
Posts: 2
Joined: January 6th, 2013, 7:46 pm

Post processing status code troubles with my PP script

Post by greenythebeast »

I use my own post processing script to process all of my Sickbeard downloads. It can be seen below:

Code: Select all

#!/usr/bin/env python
import httplib
import subprocess
import sys
import os
import shutil

source_path = sys.argv[1]
file_name = sys.argv[3]
category = sys.argv[5]
pp_status = sys.argv[7]
move_dir = "/mnt/user/Downloads/"

if pp_status == 0:
	currentDir = os.path.abspath(source_path)
	filesInCurDir = os.listdir(currentDir)
	for file in filesInCurDir:
		curFile = os.path.join(currentDir, file)
		if os.path.isfile(curFile):
			curFileExtension = curFile[-3:]
			if curFileExtension in ['avi', 'mkv', 'mp4'] and not "sample" in curFile:
				try:
					shutil.move(curFile, move_dir)
				except shutil.Error:
					print "\nDestination path " + curFile + " already exists"
	shutil.rmtree(currentDir)

	with open(os.devnull) as devnull:
		subprocess.call(['curl', '-s', '-F', 'token=*****', '-F', 'user=*****', '-F', 'title=Download Finished', '-F', 'message=' + file_name, 'https://api.pushover.net/1/messages.json'], stdout=devnull, stderr=devnull)

	connection = httplib.HTTPConnection('*****')
	body_content = '<action><name>forceLibraryRefresh</name></action>'
	headers = { "Content-type": "text/xml" }
	connection.request('POST', '/rest/action' , body_content , headers)
	result = connection.getresponse()
	if result.status == 200:
		print "\nUpdated Serviio Library"
	else:
		print "\nUpdate Failed"
elif pp_status != 0:
	with open(os.devnull) as devnull:
		subprocess.call(['curl', '-s', '-F', 'token=*****', '-F', 'user=*****', '-F', 'title=Download Failed', '-F', 'message=' + file_name, 'https://api.pushover.net/1/messages.json'], stdout=devnull, stderr=devnull)
I tested a download that returned the following post processing parameters:

Code: Select all

please sanitize before posting
As you can see, the post-processing code returned was 0. However, my script followed the 'elif pp_status != 0:' condition and sent the Download failed notification. Is something wrong with my PP script that is causing this to happen? I'm not a Python expert so if anybody could point out any logic faults in my script that would be great. Thanks for your help!
User avatar
jcfp
Release Testers
Release Testers
Posts: 1004
Joined: February 7th, 2008, 12:45 pm

Re: Post processing status code troubles with my PP script

Post by jcfp »

greenythebeast wrote:

Code: Select all

if pp_status == 0:
Proper quoting is an essential part of programming... hint: '0'
Post Reply