Пример #1
0
    def _move(self,
              subdirectory_map,
              reserved_overlays_common,
              runtime_overlays,
              env_overlays,
              testfile_global_overlays,
              etce_config_overlays,
              publishdir,
              logdir):
        skipfiles = (TestDirectory.CONFIGFILENAME,
                     TestDirectory.HOSTFILENAME)

        omitdirs = (TestDirectory.DOCSUBDIRNAME,)

        for relname, entry in subdirectory_map.items():
            if entry.root_sub_entry in omitdirs:
                continue

            # full path to the first level entry
            first_level_entry_abs = entry.root_sub_entry_absolute

            reserved_overlays = copy.copy(reserved_overlays_common)

            # first_level_entry is a nodename if it is a directory
            if entry.root_sub_entry_is_dir:
                reserved_overlays['etce_hostname'] = entry.root_sub_entry

                if logdir:
                    reserved_overlays['etce_log_path'] = os.path.join(logdir, entry.root_sub_entry)

            # for non-template file, overlays maps are searched in precedence:
            #
            # 1. reserved overlays
            # 2. runtime overlays (passed in by user or calling function)
            # 3. overlays set by environment variable
            # 4. overlays set in the test.xml file that apply to all files (at
            #    the top level)
            # 5. overlays set in the etce.conf "overlays" section - default
            #    values
            overlays = ChainMap(reserved_overlays,
                                runtime_overlays,
                                env_overlays,
                                testfile_global_overlays,
                                etce_config_overlays)

            fulldstfile = os.path.join(publishdir, relname)

            dstfiledir = os.path.dirname(fulldstfile)

            if not os.path.exists(dstfiledir):
                os.makedirs(dstfiledir)

            if relname == TestDirectory.TESTFILENAME:
                self._testdoc.rewrite_without_overlays_and_templates(fulldstfile)
            elif relname in skipfiles:
                shutil.copyfile(entry.full_name, fulldstfile)
            else:
                format_file(entry.full_name, fulldstfile, overlays)
Пример #2
0
    def _createfile(self,
                    publishdir,
                    logdir,
                    index,
                    runtime_overlays,
                    env_overlays,
                    etce_config_overlays):
        reserved_overlays = {}
        
        reserved_overlays['etce_index'] = index

        # etce_hostname formats are limited to the index and the
        # overlays specified in the test.xml file.
        etce_hostname_cm = ChainMap({'etce_index': reserved_overlays['etce_index']},
                                    self._template_local_overlaylists[index],
                                    self._template_local_overlays,
                                    self._templates_global_overlaylists[index],
                                    self._global_overlays)
            
        reserved_overlays['etce_hostname'] = format_string(self._hostname_format, etce_hostname_cm)

        if logdir:
            reserved_overlays['etce_log_path'] = \
                os.path.join(logdir, reserved_overlays['etce_hostname'])

        publishfile = os.path.join(publishdir, 
                                   reserved_overlays['etce_hostname'], 
                                   self._output_file_name)

        other_keys = set([])

        non_reserved_overlays = [ runtime_overlays,
                                  env_overlays,
                                  self._template_local_overlaylists[index],
                                  self._template_local_overlays,
                                  self._templates_global_overlaylists[index],
                                  self._global_overlays,
                                  etce_config_overlays ] 

        map(other_keys.update, non_reserved_overlays)

        key_clashes =  other_keys.intersection(set(reserved_overlays.keys()))

        if key_clashes:
            raise ValueError('Overlay keys {%s} are reserved. Quitting.' % \
                             ','.join(map(str,key_clashes)))

        overlays = ChainMap(reserved_overlays, *non_reserved_overlays)

        # format str can add subdirectories, so make those if necessary
        if not os.path.exists(os.path.dirname(publishfile)):
            os.makedirs(os.path.dirname(publishfile))

        if os.path.exists(publishfile):
            print 'Warning: %s already exists. Overwriting!' % publishfile

        format_file(self._absname, publishfile, overlays)
    def _createdir(self,
                   subdirectory_map,
                   publishdir,
                   logdir,
                   index,
                   runtime_overlays,
                   env_overlays,
                   etce_config_overlays):
        # assemble the format dictionary from the various overlays
        # most local value takes precedent
        reserved_overlays = {}

        reserved_overlays['etce_index'] = index

        # etce_hostname formats are limited to the index and the
        # overlays specified in the test.xml file.
        etce_hostname_cm = ChainMap({'etce_index': reserved_overlays['etce_index']},
                                    self._template_local_overlaylists[index],
                                    self._template_local_overlays,
                                    self._templates_global_overlaylists[index],
                                    self._global_overlays)
        
        reserved_overlays['etce_hostname'] = format_string(self._hostname_format, etce_hostname_cm)

        if logdir:
            reserved_overlays['etce_log_path'] = \
                os.path.join(logdir, reserved_overlays['etce_hostname'])
            
        node_publishdir = os.path.join(publishdir, reserved_overlays['etce_hostname'])

        non_reserved_overlays = [ runtime_overlays,
                                  env_overlays,
                                  self._template_local_overlaylists[index],
                                  self._template_local_overlays,
                                  self._templates_global_overlaylists[index],
                                  self._global_overlays,
                                  etce_config_overlays ] 
        
        other_keys = set([])

        for some_overlays in non_reserved_overlays:
            other_keys.update(some_overlays)

        key_clashes =  other_keys.intersection(set(reserved_overlays))

        if key_clashes:
            raise ValueError('Overlay keys {%s} are reserved. Quitting.' % \
                             ','.join(map(str,key_clashes)))

        overlays = ChainMap(reserved_overlays, *non_reserved_overlays)

        print('Processing template directory "%s" for etce_index=%d ' \
              'and destination=%s' % \
              (self.template_directory_name, index, node_publishdir))

        if not os.path.exists(node_publishdir):
            os.makedirs(node_publishdir)


        found = False

        for relpath,entry in subdirectory_map.items():
            # ignore files outside of the template directory
            pathtoks = relpath.split(os.path.sep)
            
            if not pathtoks[0] == self.template_directory_name:
                continue
            
            dstfile = os.path.join(node_publishdir,*pathtoks[1:])

            dstdir = os.path.dirname(dstfile)
            
            if not os.path.exists(dstdir):
                os.makedirs(dstdir)

            format_file(entry.full_name, dstfile, overlays)