configurationengine/source/plugins/symbian/ConeImagePlugin/imageplugin/generators.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    18 '''
    18 '''
    19 
    19 
    20 
    20 
    21 import re
    21 import re
    22 import os
    22 import os
    23 import sys
       
    24 import logging
    23 import logging
    25 import subprocess
    24 import subprocess
    26 import shutil
    25 import shutil
    27 
    26 
    28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    29 from cone.public import utils, exceptions
    28 from cone.public import utils
    30 
    29 
    31 class InvalidInputFileException(RuntimeError):
    30 class InvalidInputFileException(RuntimeError):
    32     """
    31     """
    33     Exception thrown in case of an invalid input file list.
    32     Exception thrown in case of an invalid input file list.
    34     """
    33     """
    58     def get_outputpath(self):
    57     def get_outputpath(self):
    59         """
    58         """
    60         Get the confml ref value from configuration if the outputpath is actually a ref
    59         Get the confml ref value from configuration if the outputpath is actually a ref
    61         """
    60         """
    62         if self._outputpath and ConfmlRefs.is_confml_ref(self._outputpath):
    61         if self._outputpath and ConfmlRefs.is_confml_ref(self._outputpath):
    63              oref = ConfmlRefs.get_confml_ref(self._outputpath)
    62             oref = ConfmlRefs.get_confml_ref(self._outputpath)
    64              opath = self.configuration.get_default_view().get_feature(oref).get_value()
    63             opath = self.configuration.get_default_view().get_feature(oref).get_value()
    65              if opath == None: 
    64             if opath == None: 
    66                  logging.getLogger('cone.imageml').warning('Output path not set.')
    65                 logging.getLogger('cone.imageml').warning('Output path not set.')
    67                  return self._outputpath 
    66                 return self._outputpath 
    68                  #raise exceptions.NotBound("Output path reference has no value %s" % oref)
    67                 #raise exceptions.NotBound("Output path reference has no value %s" % oref)
    69              (drive,opath) = os.path.splitdrive(opath)
    68             (drive,opath) = os.path.splitdrive(opath)
    70              opath = utils.resourceref.norm(opath)
    69             opath = utils.resourceref.norm(opath)
    71              opath = utils.resourceref.remove_begin_slash(opath)
    70             opath = utils.resourceref.remove_begin_slash(opath)
    72              return opath
    71             return opath
    73         else:
    72         else:
    74              return self._outputpath
    73             return self._outputpath
    75 
    74 
    76     def set_outputpath(self, value): 
    75     def set_outputpath(self, value): 
    77         self._outputpath = value
    76         self._outputpath = value
    78 
    77 
    79     def del_outputpath(self): 
    78     def del_outputpath(self): 
   136 
   135 
   137 class Command(object):
   136 class Command(object):
   138     def __init__(self,generator):
   137     def __init__(self,generator):
   139         self._generator = generator
   138         self._generator = generator
   140         self._workdir = 'conversion_workdir'
   139         self._workdir = 'conversion_workdir'
       
   140         self._extraparams = ""
       
   141         
   141 
   142 
   142     def execute(self):
   143     def execute(self):
   143         """ Execute this command """
   144         """ Execute this command """
   144         pass
   145         pass
   145 
   146 
   201         return self._generator
   202         return self._generator
   202 
   203 
   203     @property
   204     @property
   204     def workdir(self):
   205     def workdir(self):
   205         return self._workdir
   206         return self._workdir
       
   207 
       
   208     @property
       
   209     def extraparams(self):
       
   210         if self._generator.extraparams and self._generator.configuration:
       
   211             dview = self._generator.configuration.get_default_view()
       
   212             return utils.expand_refs_by_default_view(self._generator.extraparams, dview)
       
   213         else:
       
   214             return self._generator.extraparams or ''
   206     
   215     
   207     def _get_filtered_input_files(self):
   216     def _get_filtered_input_files(self):
   208         """
   217         """
   209         Get the list of InputFile objects and with ignored
   218         Get the list of InputFile objects and with ignored
   210         (optional empty or invalid files) entries filtered out.
   219         (optional empty or invalid files) entries filtered out.
   251         """
   260         """
   252         input_files = self._get_filtered_input_files()
   261         input_files = self._get_filtered_input_files()
   253         if len(input_files) == 0: return 0
   262         if len(input_files) == 0: return 0
   254         self.create_workdir(input_files)
   263         self.create_workdir(input_files)
   255         
   264         
   256         if not os.path.exists(os.path.dirname(self.generator.path)):
   265         opath = self.generator.path
   257             os.makedirs(os.path.dirname(self.generator.path))
   266         odir = os.path.dirname(opath)
       
   267         if odir and not os.path.exists(odir):
       
   268             os.makedirs(odir)
   258         
   269         
   259         command = self.get_command(input_files)
   270         command = self.get_command(input_files)
   260         p = subprocess.Popen(command,
   271         p = subprocess.Popen(command,
   261                              stdout=subprocess.PIPE,
   272                              stdout=subprocess.PIPE,
   262                              stderr=subprocess.PIPE)
   273                              stderr=subprocess.PIPE)
   271         if p.returncode != 0:
   282         if p.returncode != 0:
   272             logging.getLogger('cone.bmconv').error("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   283             logging.getLogger('cone.bmconv').error("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   273         else:
   284         else:
   274             logging.getLogger('cone.bmconv').info("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   285             logging.getLogger('cone.bmconv').info("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   275         if p.returncode == 0:
   286         if p.returncode == 0:
   276         	self.clean_workdir()
   287             self.clean_workdir()
   277         return p.returncode 
   288         return p.returncode 
   278 
   289 
   279     def get_command(self, input_files):
   290     def get_command(self, input_files):
   280         command = [self.tool]
   291         command = [self.tool]
       
   292         
       
   293         """ Add extraparams """
       
   294         if hasattr(self._generator,'extraparams'):
       
   295             command.append(self.extraparams)
       
   296         
   281         """ Add palette file """
   297         """ Add palette file """
   282         if hasattr(self._generator,'palette'):
   298         if hasattr(self._generator,'palette'):
   283             command.append('/p%s' % os.path.abspath(self.generator.palette))
   299             command.append('/p%s' % os.path.abspath(self.generator.palette))
   284 
   300         
   285         """ Add output file """
   301         """ Add output file """
   286         """ Add output file as compressed if needed """
   302         """ Add output file as compressed if needed """
   287         if self.rom:
   303         if self.rom:
   288             if self.compress:
   304             if self.compress:
   289                 command.append('/s')
   305                 command.append('/s')
   362         if p.returncode != 0:
   378         if p.returncode != 0:
   363             logging.getLogger('cone.mifconv').error("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   379             logging.getLogger('cone.mifconv').error("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   364         else:
   380         else:
   365             logging.getLogger('cone.mifconv').info("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   381             logging.getLogger('cone.mifconv').info("Command returned with returncode %s: %s" % (p.returncode, ' '.join(command)))
   366         if p.returncode == 0:
   382         if p.returncode == 0:
   367 	        self.clean_workdir()
   383             self.clean_workdir()
   368         return p.returncode 
   384         return p.returncode 
   369 
   385 
   370     def get_command(self, input_files):
   386     def get_command(self, input_files):
   371         command = [self.tool]
   387         command = [self.tool]
   372         
   388         
   373         """ Add output file """
   389         """ Add output file """
   374         command.append(os.path.normpath(self.generator.path))
   390         command.append(os.path.normpath(self.generator.path))
       
   391         
       
   392         """ Add extraparams """
       
   393         if hasattr(self._generator,'extraparams'):
       
   394             command.append(self.extraparams)
   375         
   395         
   376         """ Add temp_path """
   396         """ Add temp_path """
   377         command.append("/t%s" % self.temppath)
   397         command.append("/t%s" % self.temppath)
   378         
   398         
   379         # Add tool directory if given
   399         # Add tool directory if given