예제 #1
0
    def get_filename(self,
                     configuration,
                     full_path=None,
                     filename=None,
                     dirname=None,
                     basename=None,
                     prefix=None,
                     suffix=None,
                     overwrite=True,
                     series=False,
                     series_padding=3):
        # if prefix/suffix/series are overridden, want to use them
        # instead of name...
        if full_path is None:
            # use file if overridden or none of the file params are
            # overridden and the file is not None

            overwrite = configuration['overwrite']
            if (configuration.has_override('file')
                    or (not (configuration.has_override('basename')
                             or configuration.has_override('prefix')
                             or configuration.has_override('suffix')
                             or configuration.has_override('dir')
                             or configuration.has_override('series')
                             or configuration.has_override('seriesPadding')
                             or configuration.has_override('seriesStart'))
                        and 'file' in configuration
                        and configuration['file'] is not None)):
                full_path = configuration['file']
            else:
                if configuration['basename'] is not None:
                    basename = configuration['basename']
                if configuration['prefix'] is not None:
                    prefix = configuration['prefix']
                if configuration['suffix'] is not None:
                    suffix = configuration['suffix']
                if configuration['dir'] is not None:
                    dirname = configuration['dir']
                if configuration['series'] is not None:
                    series = configuration['series']
                if configuration['seriesPadding'] is not None:
                    series_padding = configuration['seriesPadding']

        if full_path is None:
            # should any of these necessitate series=True?
            if basename is None:
                basename = 'vt_out'
            if prefix is None:
                prefix = ''
            if suffix is None:
                suffix = ''
            if dirname is None:
                dirname = ''
            if not os.path.isabs(dirname):
                vt_output_dir = getattr(get_vistrails_temp_configuration(),
                                        'outputDirectory', None)
                if vt_output_dir:
                    dirname = os.path.join(vt_output_dir, dirname)

            # seriesPadding and series have defaults so no
            # need to default them

            if not overwrite and series:
                # need to find first open slot
                full_path = None
                while full_path is None or os.path.exists(full_path):
                    series_str = (("%%0%dd" % series_padding) %
                                  self.get_series_num())
                    full_path = os.path.join(
                        dirname,
                        "%s%s%s%s" % (prefix, basename, series_str, suffix))
            else:
                if series:
                    series_str = (("%%0%dd" % series_padding) %
                                  self.get_series_num())
                else:
                    series_str = ""
                full_path = os.path.join(
                    dirname,
                    "%s%s%s%s" % (prefix, basename, series_str, suffix))
            if not overwrite and os.path.exists(full_path):
                raise IOError('File "%s" exists and overwrite is False' %
                              full_path)

        return full_path
예제 #2
0
 def get_override(cls, k):
     config = get_vistrails_temp_configuration().outputSettings
     str_val = cls.get_from_config(config, k)
     return cls.get_field(k).from_string(str_val)
예제 #3
0
 def has_override(cls, k):
     config = get_vistrails_temp_configuration().outputSettings
     return cls.has_from_config(config, k)
예제 #4
0
 def get_override(cls, k):
     config = get_vistrails_temp_configuration().outputSettings
     str_val = cls.get_from_config(config, k)
     return cls.get_field(k).from_string(str_val)
예제 #5
0
 def has_override(cls, k):
     config = get_vistrails_temp_configuration().outputSettings
     return cls.has_from_config(config, k)
예제 #6
0
    def get_filename(self, configuration, full_path=None, filename=None,
                     dirname=None, basename=None, prefix=None, suffix=None,
                     overwrite=True, series=False, series_padding=3):
        # if prefix/suffix/series are overridden, want to use them
        # instead of name...
        if full_path is None:
            # use file if overridden or none of the file params are
            # overridden and the file is not None

            overwrite = configuration['overwrite']
            if (configuration.has_override('file') or
                (not (configuration.has_override('basename') or
                      configuration.has_override('prefix') or
                      configuration.has_override('suffix') or
                      configuration.has_override('dir') or
                      configuration.has_override('series') or
                      configuration.has_override('seriesPadding') or
                      configuration.has_override('seriesStart')) and
                 'file' in configuration and
                 configuration['file'] is not None)):
                full_path = configuration['file']
            else:
                if configuration['basename'] is not None:
                    basename = configuration['basename']
                if configuration['prefix'] is not None:
                    prefix = configuration['prefix']
                if configuration['suffix'] is not None:
                    suffix = configuration['suffix']
                if configuration['dir'] is not None:
                    dirname = configuration['dir']
                if configuration['series'] is not None:
                    series = configuration['series']
                if configuration['seriesPadding'] is not None:
                    series_padding = configuration['seriesPadding']

        if full_path is None:                
            # should any of these necessitate series=True?
            if basename is None:
                basename = 'vt_out'
            if prefix is None:
                prefix = ''
            if suffix is None:
                suffix = ''
            if dirname is None:
                dirname = ''
            if not os.path.isabs(dirname):
                vt_output_dir = getattr(get_vistrails_temp_configuration(),
                                        'outputDirectory',
                                        None)
                if vt_output_dir:
                    dirname = os.path.join(vt_output_dir, dirname)

            # seriesPadding and series have defaults so no
            # need to default them

            if not overwrite and series:
                # need to find first open slot
                full_path = None
                while full_path is None or os.path.exists(full_path):
                    series_str = (("%%0%dd" % series_padding) % 
                                  self.get_series_num())
                    full_path = os.path.join(dirname, "%s%s%s%s" % 
                                             (prefix, basename, 
                                              series_str, suffix))
            else:
                if series:
                    series_str = (("%%0%dd" % series_padding) % 
                                  self.get_series_num())
                else:
                    series_str = ""
                full_path = os.path.join(dirname, "%s%s%s%s" % 
                                         (prefix, basename, series_str, 
                                          suffix))
            if not overwrite and os.path.exists(full_path):
                raise IOError('File "%s" exists and overwrite is False' % full_path)

        return full_path