示例#1
0
 def Create(self, finder):
     """Create the module which consists of declaration statements for each
     of the values."""
     today = datetime.datetime.today()
     source_timestamp = 0
     for module in finder.modules:
         if module.file is None:
             continue
         if module.source_is_zip_file:
             continue
         if not os.path.exists(module.file):
             raise ConfigError(
                 f"No file named {module.file} (for module {module.name})"
             )
         timestamp = os.stat(module.file).st_mtime
         source_timestamp = max(source_timestamp, timestamp)
     stamp = datetime.datetime.fromtimestamp(source_timestamp)
     self.values["BUILD_TIMESTAMP"] = today.strftime(self.time_format)
     self.values["BUILD_HOST"] = socket.gethostname().split(".")[0]
     self.values["SOURCE_TIMESTAMP"] = stamp.strftime(self.time_format)
     module = finder._AddModule(self.module_name)
     source_parts = []
     names = list(self.values.keys())
     names.sort()
     for name in names:
         value = self.values[name]
         source_parts.append(f"{name} = {value!r}")
     source = "\n".join(source_parts)
     module.code = compile(source, "%s.py" % self.module_name, "exec")
     return module
示例#2
0
 def Create(self, finder):
     """Create the module which consists of declaration statements for each
     of the values."""
     today = datetime.datetime.today()
     source_timestamp = 0
     for module in finder.modules:
         if module.file is None:
             continue
         if module.source_is_zip_file:
             continue
         if not os.path.exists(module.file):
             raise ConfigError(
                 f"No file named {module.file} (for module {module.name})")
         timestamp = os.stat(module.file).st_mtime
         source_timestamp = max(source_timestamp, timestamp)
     stamp = datetime.datetime.fromtimestamp(source_timestamp)
     self.values["BUILD_TIMESTAMP"] = today.strftime(self.time_format)
     self.values["BUILD_HOST"] = socket.gethostname().split(".")[0]
     self.values["SOURCE_TIMESTAMP"] = stamp.strftime(self.time_format)
     source_parts = []
     names = list(self.values.keys())
     names.sort()
     for name in names:
         value = self.values[name]
         source_parts.append(f"{name} = {value!r}")
     filename = os.path.join(tempfile.gettempdir(), f"{uuid.uuid4()}.py")
     with open(filename, "w") as fp:
         fp.write("\n".join(source_parts))
     module = finder.IncludeFile(filename, self.module_name)
     os.remove(filename)
     return module