From: Benoît Pin Date: Mon, 25 Oct 2010 20:04:49 +0000 (+0200) Subject: Copie de photoprint depuis : X-Git-Url: https://scm.cri.mines-paristech.fr/git/photoprint.git/commitdiff_plain/bddfc31eaf67003a04f79f7cf168b8d840920fd6?ds=sidebyside Copie de photoprint depuis : URL: http://svn.luxia.fr/svn/labo/projects/zope/photoprint/trunk Repository Root: http://svn.luxia.fr/svn/labo Repository UUID: 7eb47c9a-6e02-46bb-968b-2b2bf1974b8d Revision: 1390 Node Kind: directory Schedule: normal Last Changed Author: pin Last Changed Rev: 1357 Last Changed Date: 2009-09-07 18:06:05 +0200 (Lun, 07 sep 2009) --- bddfc31eaf67003a04f79f7cf168b8d840920fd6 diff --git a/__init__.py b/__init__.py new file mode 100755 index 0000000..72d13c0 --- /dev/null +++ b/__init__.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################ +# Copyright © 2009 Benoît PIN # +# Cliché - http://luxia.fr # +# # +# This program is free software; you can redistribute it # +# and/or modify it under the terms of the Creative Commons # +# "Attribution-Noncommercial 2.0 Generic" # +# http://creativecommons.org/licenses/by-nc/2.0/ # +############################################################ +""" +Photo print product. Used to order photo prints. + +$Id: __init__.py 1100 2009-06-01 21:48:59Z pin $ +$URL: http://svn.luxia.fr/svn/labo/projects/zope/photoprint/trunk/__init__.py $ +""" +from Products.CMFCore import utils as cmfutils +import tool +import utils +import order +import cart +import exceptions + + +tools = (tool.PhotoPrintTool,) + +def initialize(registrar) : + cmfutils.ToolInit('Photoprint Tool', + tools = tools, + icon = 'tool.gif' + ).initialize(registrar) diff --git a/_utils/import_printing_list.py b/_utils/import_printing_list.py new file mode 100755 index 0000000..5e8e303 --- /dev/null +++ b/_utils/import_printing_list.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#################################################### +# Copyright © 2009 Luxia SAS. All rights reserved. # +# # +# Contributors: # +# - Benoît Pin # +#################################################### +""" +Downloads RSS based order description and make a local human readable file tree +to facilitate printing tasks. + +$Id: import_printing_list.py 1153 2009-06-12 14:07:29Z pin $ +$URL: http://svn.luxia.fr/svn/labo/projects/zope/photoprint/trunk/_utils/import_printing_list.py $ +""" + + +from urllib2 import HTTPBasicAuthHandler +from urllib2 import build_opener +from urllib2 import urlopen +from xml.dom.minidom import parseString +from xml.dom import Node +from os import mkdir, chdir +from os.path import abspath, join, expanduser, exists +from getpass import getpass + +ELEMENT_NODE = Node.ELEMENT_NODE + +def getHttpOpener(url, login, password) : + auth_handler = HTTPBasicAuthHandler() + host = '/'.join(url.split('/', 3)[:3]) + auth_handler.add_password('Zope', host, login, password) + opener = build_opener(auth_handler) + return opener + +def getXml(url, opener) : + url = '%s?disable_cookie_login__=1' % url + xml = opener.open(url).read() + return xml + +def genFileTree(url, login, password, dest) : + opener = getHttpOpener(url, login, password) + xml = getXml(url, opener) + d = parseString(xml) + doc = d.documentElement + + channel = doc.getElementsByTagName('channel')[0] + orderName = getContentOf(channel, 'title') + + chdir(dest) + mkdir(orderName) + + for item in iterElementChildsByTagName(d.documentElement, 'item') : + ppTitle = getContentOf(item, 'pp:title') + ppQuantity = getContentOf(item, 'pp:quantity') + + printTypePath = join(orderName, ppTitle) + printQuantityPath = join(orderName, ppTitle, ppQuantity) + + if not exists(printTypePath) : + mkdir(printTypePath) + infoFile = open(join(printTypePath, 'info.txt'), 'w') + infoFile.write(getContentOf(item, 'pp:title')) + infoFile.write('\n\n') + infoFile.write(getContentOf(item, 'pp:description')) + infoFile.close() + + if not exists(printQuantityPath) : + mkdir(printQuantityPath) + + hdUrl = '%s?disable_cookie_login__=1' % getContentOf(item, 'link') + localFileName = getContentOf(item, 'title') + print localFileName + localFile = open(join(printQuantityPath, localFileName), 'w') + localFile.write(opener.open(hdUrl).read()) + localFile.close() + +def iterElementChildsByTagName(parent, tagName) : + child = parent.firstChild + while child : + if child.nodeType == ELEMENT_NODE and child.tagName == tagName : + yield child + child = child.nextSibling + +def getContentOf(parent, tagName) : + child = parent.firstChild + while child : + if child.nodeType == ELEMENT_NODE and child.tagName == tagName : + return child.firstChild.nodeValue.encode('utf-8') + child = child.nextSibling + + raise ValueError("%r tag not found" % tagName) + + +def main() : + url = raw_input('url flux xml de la commande : ') + login = raw_input('login : ') + password = getpass('mot de passe : ') + dest = raw_input('cible [~/Desktop]') + if not dest : + dest = expanduser('~/Desktop') + + genFileTree(url, login, password, dest) + +if __name__ == '__main__' : + main() + + diff --git a/cart.py b/cart.py new file mode 100644 index 0000000..fef5a85 --- /dev/null +++ b/cart.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +#################################################### +# Copyright © 2009 Luxia SAS. All rights reserved. # +# # +# Contributors: # +# - Benoît Pin # +#################################################### +""" Cart definition used to store buyable prints + +$Id$ +$URL$ +""" +from Globals import InitializeClass, Persistent, PersistentMapping +from Acquisition import Implicit +from AccessControl import ModuleSecurityInfo +from Products.CMFCore.utils import getToolByName +from exceptions import SoldOutError, CartLockedError +from tool import COPIES_COUNTERS +from order import CopiesCounters + +from logging import getLogger +console = getLogger('Products.photoprint.cart') + +CART_ITEM_KEYS = ['cmf_uid', 'printing_template', 'quantity'] + +msecurity = ModuleSecurityInfo('Products.photoprint.cart') +msecurity.declarePublic('PrintCart') + +class PrintCart(Persistent, Implicit) : + """ + items are store like that: + {: + {