[web/request] don't convert request parameters if py3k
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""cubicweb-ctl commands and command handlers common to twisted/modpythonweb configuration"""from__future__importprint_function__docformat__="restructuredtext en"importos,os.pathasospfromshutilimportcopy,rmtreefromlogilab.common.shellutilsimportASKfromcubicwebimportExecutionErrorfromcubicweb.cwctlimportCWCTLfromcubicweb.cwconfigimportCubicWebConfigurationascwcfgfromcubicweb.toolsutilsimportCommand,CommandHandler,underline_titletry:fromosimportsymlinkaslinkdirexceptImportError:fromshutilimportcopytreeaslinkdirclassWebCreateHandler(CommandHandler):cmdname='create'defbootstrap(self,cubes,automatic=False,inputlevel=0):"""bootstrap this configuration"""ifnotautomatic:print('\n'+underline_title('Generic web configuration'))config=self.configconfig.input_config('web',inputlevel)ifASK.confirm('Allow anonymous access ?',False):config.global_set_option('anonymous-user','anon')config.global_set_option('anonymous-password','anon')defpostcreate(self,*args,**kwargs):"""hooks called once instance's initialization has been completed"""classGenStaticDataDirMixIn(object):"""Create a directory merging all data directory content from cubes and CW. """defgenerate_static_dir(self,config,dest=None,ask_clean=False,repo=None):ifnotdest:dest=config['staticdir-path']ifnotdest:dest=osp.join(config.appdatahome,'data')ifosp.exists(dest):if(notask_cleanornot(config.verbosityandASK.confirm('Remove existing data directory %s?'%dest))):raiseExecutionError('Directory %s already exists. ''Remove it first.'%dest)rmtree(dest)config.quick_start=True# notify this is not a regular start# list all resources (no matter their order)resources=set()fordatadirinself._datadirs(config,repo=repo):fordirpath,dirnames,filenamesinos.walk(datadir):rel_dirpath=dirpath[len(datadir)+1:]resources.update(osp.join(rel_dirpath,f)forfinfilenames)# locate resources and copy them to destinationforresourceinresources:dest_resource=osp.join(dest,resource)dirname=osp.dirname(dest_resource)ifnotosp.isdir(dirname):os.makedirs(dirname)resource_dir,resource_path=config.locate_resource(resource)copy(osp.join(resource_dir,resource_path),dest_resource)# handle md5 version subdirectorylinkdir(dest,osp.join(dest,config.instance_md5_version()))print('You can use apache rewrite rule below :\n''RewriteRule ^/data/(.*) %s/$1 [L]'%dest)def_datadirs(self,config,repo=None):ifrepoisNone:repo=config.repository()ifconfig._cubesisNone:# web only configconfig.init_cubes(repo.get_cubes())forcubeinrepo.get_cubes():cube_datadir=osp.join(cwcfg.cube_dir(cube),'data')ifosp.isdir(cube_datadir):yieldcube_datadiryieldosp.join(config.shared_dir(),'data')classWebUpgradeHandler(CommandHandler,GenStaticDataDirMixIn):cmdname='upgrade'defpostupgrade(self,repo):config=self.configifnotconfig['generate-staticdir']:returnself.generate_static_dir(config,ask_clean=True,repo=repo)classGenStaticDataDir(Command,GenStaticDataDirMixIn):"""Create a directory merging all data directory content from cubes and CW. """name='gen-static-datadir'arguments='<instance> [dirpath]'min_args=1max_args=2options=()defrun(self,args):appid=args.pop(0)config=cwcfg.config_for(appid)dest=Noneifargs:dest=args[0]self.generate_static_dir(config,dest)CWCTL.register(GenStaticDataDir)