78""" The default mapper. It splits the content based on size characteristics.
+ 79
+ 80 'the max.files.per.archive' and 'max.uncompressed.size' properties define how the input files
+ 81 are split between a number of part zips.
+ 82 """
+
183""" Implements a policy content mapper.
+184
+185 It transforms a list of files into a list of commands with their inputs.
+186 All files with policy 0 will be under the main archive.
+187 All other files will get backed up by policy and then store into an second archive.
+188 """
+189
+
276""" Get policy value for a specific directory. """
+277dirname=os.path.normpath(dirname)
+278ifnotself._policy_cache.has_key(dirname):
+279policyfile=None
+280fornameinself.get_policy_filenames():
+281ifsys.platform!='win32':
+282forfilenameinos.listdir(dirname):
+283iffilename.lower()==name.lower():
+284policyfile=os.path.join(dirname,filename)
+285break
+286elifos.path.exists(os.path.join(dirname,name)):
+287policyfile=os.path.join(dirname,name)
+288break
+289
+290value=self._config.get('policy.default.value',MISSING_POLICY)
+291ifpolicyfile!=None:
+292try:
+293value=fileutils.read_policy_content(policyfile)
+294ifvaluenotinself._binary.keys():
+295_logger.error("POLICY_ERROR: policy file found %s but policy %s value not exists in csv"%(policyfile,value))
+296exceptException,exc:
+297_logger.error("POLICY_ERROR: %s"%exc)
+298value=self._config.get('policy.default.value',MISSING_POLICY)
+299else:
+300_logger.error("POLICY_ERROR: could not find a policy file under: '%s'"%dirname)
+301# saving the policy value for that directory.
+302self._policy_cache[dirname]=value
+303returnself._policy_cache[dirname]
+
310""" Store the input file sorted by its policy number. """
+311path=os.path.join(self._config['root.dir'],filename)
+312parentdir=os.path.dirname(path)
+313ifos.path.isdir(path):
+314parentdir=path
+315value=self.get_dir_policy(parentdir)
+316ifnotvalueinself._policies:
+317self._policies[value]=codecs.open(os.path.join(self._config['temp.build.dir'],self._config['name']+"_%s"%value+".txt"),"w+","utf-8")
+318self._policies[value].write(u"%s\n"%filename)
+
322""" This class implements a variant of the policy mapper.
+323
+324 It removes the internal source. Only binary flagged content is kept.
+325 """
+326
+
333""" Return the policy.root.dir or root.dir if not set or not under root.dir."""
+334ifnotself._config.has_key("policy.root.dir"):
+335returnos.path.normpath(self._config['root.dir'])
+336else:
+337iffileutils.destinsrc(self._config['root.dir'],self._config['policy.root.dir']):
+338returnos.path.normpath(self._config['policy.root.dir'])
+339else:
+340returnos.path.normpath(self._config['root.dir'])
+
343""" check if the directory should be dropped or not"""
+344dirname=os.path.normpath(dirname)
+345# check if parent is banned...
+346prootdir=os.path.normpath(self.get_policy_root_dir())
+347rootdir=os.path.normpath(self._config['root.dir'])
+348ifsys.platform=='win32':
+349dirname=dirname.lower()
+350prootdir=prootdir.lower()
+351rootdir=rootdir.lower()
+352
+353# else get real value...
+354ifnotself._rm_policy_cache.has_key(dirname):
+355self._rm_policy_cache[dirname]=self.get_dir_policy(dirname)
+356
+357returnself._rm_policy_cache[dirname]
+
360""" Generates a list of build commands. """
+361stages=PolicyMapper.create_commands(self,manifest)
+362
+363ifnotself._config.has_key('policy.csv'):
+364_logger.error("POLICY_ERROR: Property 'policy.csv' not defined everything will get removed.")
+365cmds=[]
+366file_handle=codecs.open(manifest,"r","utf-8")
+367forlineinfile_handle.readlines():
+368line=line.rstrip()
+369filepath=os.path.normpath(os.path.join(self._config.get('zip.root.dir',self._config['root.dir']),line))
+370value=self.get_rmdir_policy(os.path.dirname(filepath))
+371delete=True
+372ifvalueinself._binary.keys():
+373ifself._binary[value]=="yes":
+374_logger.info("POLICY_INFO: Keeping %s (%s=>yes)!"%(filepath,value))
+375delete=False
+376elifself._binary[value]=="bin":
+377_logger.info("POLICY_INFO: Keeping %s (%s=>bin)!"%(filepath,value))
+378delete=False
+379else:
+380_logger.error("POLICY_ERROR: %s value for %s not in csv file. Will be removed!!"%(value,filepath))
+381
+382ifdelete:
+383_logger.info("POLICY_INFO: File %s will be removed!"%filepath)
+384cmds.append(buildtools.Delete(filename=filepath))
+385file_handle.close()
+386iflen(cmds)>0:
+387stages.append(cmds)
+388returnstages
+
399""" Loading the policy using the 3rd column. """
+400_logger.info("POLICY_INFO: Loading actions from the 3rd column")
+401PolicyRemoverMapper.load_policy_binary(self,csvfile,column=3)
+
410""" Loading the policy using the 4th column. """
+411_logger.info("POLICY_INFO: Loading actions from the 4th column")
+412PolicyRemoverMapper.load_policy_binary(self,csvfile,column=4)
+
422""" Get mapper instance from its string id. """
+423ifnameinMAPPERS:
+424returnMAPPERS[name](config,archiver)
+425raiseException("ERROR: Could not find mapper '%s'."%name)
+