#!/usr/bin/python

import sys, zipfile, md5
import getopt
import gnomevfs

opt,par = getopt.getopt(sys.argv[1:],'-s:')
inpfile = gnomevfs.get_local_path_from_uri(par[0])
outfile = par[1]

try:
	zfile=zipfile.ZipFile(inpfile)
	files=zfile.namelist()
	# check for meta-file if it's really a FreeCAD document
	if files[0] != "Document.xml":
		sys.exit(1)

	image="thumbnails/Thumbnail.png"
	if image in files:
		image=zfile.read(image)
		thumb=open(outfile,"wb")
		thumb.write(image)
		thumb.close()
except:
	sys.exit(1)

