Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.05; 'say,': 0.05; 'schema': 0.05; 'class,': 0.07; 'parameter': 0.07; 'type,': 0.07; 'users,': 0.07; 'definition,': 0.09; 'parsers': 0.09; 'path.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stored': 0.10; 'files.': 0.13; 'skip:f 30': 0.15; 'different,': 0.16; 'parser.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.17; 'directory.': 0.17; 'else,': 0.17; 'module,': 0.17; 'code,': 0.18; 'module': 0.19; 'putting': 0.20; 'file.': 0.20; 'sort': 0.21; 'import': 0.21; 'parse': 0.22; 'sets': 0.23; 'somewhere': 0.24; 'pass': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'am,': 0.27; 'separate': 0.27; 'mind.': 0.27; 'header:X-Complaints-To:1': 0.28; 'decide': 0.28; 'run': 0.28; 'behavior.': 0.29; 'maybe': 0.29; 'becomes': 0.30; 'expect': 0.31; 'sense': 0.31; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'directory,': 0.33; 'to:addr :python-list': 0.33; 'know.': 0.33; 'that,': 0.34; 'wrong': 0.34; 'thanks': 0.34; 'path': 0.35; 'there': 0.35; 'received:org': 0.36; 'created': 0.36; 'explain': 0.36; 'but': 0.36; 'modules': 0.36; 'anything': 0.36; 'xml': 0.37; 'two': 0.37; 'received:co.za': 0.37; 'received:za': 0.37; 'rather': 0.37; 'well.': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'files': 0.38; 'fact': 0.38; 'some': 0.38; 'nothing': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'save': 0.61; 'tracking': 0.61; 'provide': 0.62; 'different': 0.63; 'ever': 0.63; 'more': 0.63; 'within': 0.64; 'making': 0.64; 'therefore': 0.65; 'validate': 0.65; 'received:41': 0.73; 'frank': 0.75; 'companies,': 0.78; 'etc),': 0.84; 'etc,': 0.84; 'shared,': 0.84; 'subject:find': 0.84; 'subject:Best': 0.91; 'angel': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Frank Millman Subject: Re: Best way to find starting directory Date: Wed, 20 Mar 2013 07:58:11 +0200 References: <51485E35.7090501@davea.name> <51487E55.6040704@davea.name> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 41-133-115-17.dsl.mweb.co.za User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <51487E55.6040704@davea.name> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363759111 news.xs4all.nl 6984 [2001:888:2000:d::a6]:46430 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41568 On 19/03/2013 17:03, Dave Angel wrote: > On 03/19/2013 10:29 AM, Frank Millman wrote: >> On 19/03/2013 14:46, Dave Angel wrote: >> >> As you say, there is a variety of types of data that one might to store >> externally. My current scenario is that, in my business/accounting >> application, I use xml to store form definitions, report definitions, >> etc, which are kept in the database (compressed). I am now constructing >> some xml schemas to validate the xml files. I need to store the schemas >> somewhere, so I have created a directory called 'schemas' under the main >> directory. I need to access them from various parts of the application, >> so I need a reliable way to locate the 'schemas' directory. > > Rather than having various parts of the code all figuring this sort of > thing out for themself, let them all call a common place. If there's > nothing in common but the directory, then save that as a global in some > module that multiple modules can import. But if there's more that > could/should be shared, then make a whole module, or maybe a class, > implemmnting that behavior. If nothing else, it then means there's only > one place to change when you change your mind. > >> >> In theory I could store them somewhere different, and use a parameter to >> provide the path. But they are only used within the context of the >> application, so I think it makes sense to keep them alongside the 'py' >> files that make up the application. >> > > In putting them there, you are making two assumptions. One is that only > one user will ever run this, and two is that the user will not need two > sets of those 'schemas'. If the user is tracking two different > companies, each with the same code, but different xml and different > database, this would be the wrong place to put it. But it's up to you > to decide those assumptions, not I. > Maybe I did not explain very well. I fully expect a large number of users, tracking a large number of companies, to access the same schema file at the same time. In fact I use lxml to parse the xml once it has been read from the database and decompressed. There are a limited number of 'types' of xml file (form definition, service definition, report definition, etc), and each type has its own schema. lxml will use a validating schema if you pass the path to the xsd file as a parameter to the parser. I create separate parsers, one for each type, when the program starts. But I still need to tell it where to find the xsd file. They are stored in a sub-directory called 'schemas'. Therefore when I create the parsers I have the following - import os import __main__ from lxml import etree schema_path = os.path.join( os.path.dirname(__main__.__file__), 'schemas') form_schema=etree.XMLSchema( file=os.path.join(schema_path, 'form.xsd')) form_parser = etree.XMLParser( schema=form_schema, attribute_defaults=True, remove_comments=True, remove_blank_text=True) I hope that is clearer. If you can see anything wrong with this approach, please let me know. I would much rather find out now rather than when my 'large number of users' becomes a reality! Thanks Frank