parameters: (self, path, template="default")
docstring: Generate the virtual table files
docstring_summary: Generate the virtual table files
docstring_tokens: Generate the virtual table files
function: def generate(self, path, template="default"):
          """Generate the virtual table files"""
          logging.debug("TableState.generate")
  
          all_options = []
          # Create a list of column options from the kwargs passed to the column.
          for column in self.columns():
              column_options = []
              for option in column.options:
                  # Only allow explicitly-defined options.
                  if option in COLUMN_OPTIONS:
                      column_options.append("ColumnOptions::" + COLUMN_OPTIONS[option])
                      all_options.append(COLUMN_OPTIONS[option])
                  else:
                      print(yellow(
                          "Table %s column %s contains an unknown option: %s" % (
                              self.table_name, column.name, option)))
              column.options_set = " | ".join(column_options)
              if len(column.aliases) > 0:
                  self.has_column_aliases = True
          if len(all_options) > 0:
              self.has_options = True
          if "event_subscriber" in self.attributes:
              self.generator = True
          if "strongly_typed_rows" in self.attributes:
              self.strongly_typed_rows = True
          if "cacheable" in self.attributes:
              if self.generator:
                  print(lightred(
                      "Table cannot use a generator and be marked cacheable: %s" % (path)))
                  exit(1)
          if self.table_name == "" or self.function == "":
              print(lightred("Invalid table spec: %s" % (path)))
              exit(1)
  
          # Check for reserved column names
          for column in self.columns():
              if column.name in RESERVED:
                  print(lightred(("Cannot use column name: %s in table: %s "
                                  "(the column name is reserved)" % (
                                      column.name, self.table_name))))
                  exit(1)
  
          path_bits = path.split("/")
          for i in range(1, len(path_bits)):
              dir_path = ""
              for j in range(i):
                  dir_path += "%s/" % path_bits[j]
              if not os.path.exists(dir_path):
                  try:
                      os.mkdir(dir_path)
                  except:
                      # May encounter a race when using a make jobserver.
                      pass
          logging.debug("generating %s" % path)
          self.impl_content = templite.Templite(TEMPLATES[template]).render(
              table_name=self.table_name,
              table_name_cc=to_camel_case(self.table_name),
              table_name_ucc=to_upper_camel_case(self.table_name),
              schema=self.columns(),
              header=self.header,
              impl=self.impl,
              function=self.function,
              class_name=self.class_name,
              attributes=self.attributes,
              examples=self.examples,
              aliases=self.aliases,
              has_options=self.has_options,
              has_column_aliases=self.has_column_aliases,
              generator=self.generator,
              strongly_typed_rows=self.strongly_typed_rows,
              attribute_set=[TABLE_ATTRIBUTES[attr] for attr in self.attributes if attr in TABLE_ATTRIBUTES],
          )
  
          with open(path, "w+") as file_h:
              file_h.write(self.impl_content)
function_tokens: def generate ( self , path , template = "default" ) : logging . debug ( "TableState.generate" ) all_options = [ ] # Create a list of column options from the kwargs passed to the column. for column in self . columns ( ) : column_options = [ ] for option in column . options : # Only allow explicitly-defined options. if option in COLUMN_OPTIONS : column_options . append ( "ColumnOptions::" + COLUMN_OPTIONS [ option ] ) all_options . append ( COLUMN_OPTIONS [ option ] ) else : print ( yellow ( "Table %s column %s contains an unknown option: %s" % ( self . table_name , column . name , option ) ) ) column . options_set = " | " . join ( column_options ) if len ( column . aliases ) > 0 : self . has_column_aliases = True if len ( all_options ) > 0 : self . has_options = True if "event_subscriber" in self . attributes : self . generator = True if "strongly_typed_rows" in self . attributes : self . strongly_typed_rows = True if "cacheable" in self . attributes : if self . generator : print ( lightred ( "Table cannot use a generator and be marked cacheable: %s" % ( path ) ) ) exit ( 1 ) if self . table_name == "" or self . function == "" : print ( lightred ( "Invalid table spec: %s" % ( path ) ) ) exit ( 1 ) # Check for reserved column names for column in self . columns ( ) : if column . name in RESERVED : print ( lightred ( ( "Cannot use column name: %s in table: %s " "(the column name is reserved)" % ( column . name , self . table_name ) ) ) ) exit ( 1 ) path_bits = path . split ( "/" ) for i in range ( 1 , len ( path_bits ) ) : dir_path = "" for j in range ( i ) : dir_path += "%s/" % path_bits [ j ] if not os . path . exists ( dir_path ) : try : os . mkdir ( dir_path ) except : # May encounter a race when using a make jobserver. pass logging . debug ( "generating %s" % path ) self . impl_content = templite . Templite ( TEMPLATES [ template ] ) . render ( table_name = self . table_name , table_name_cc = to_camel_case ( self . table_name ) , table_name_ucc = to_upper_camel_case ( self . table_name ) , schema = self . columns ( ) , header = self . header , impl = self . impl , function = self . function , class_name = self . class_name , attributes = self . attributes , examples = self . examples , aliases = self . aliases , has_options = self . has_options , has_column_aliases = self . has_column_aliases , generator = self . generator , strongly_typed_rows = self . strongly_typed_rows , attribute_set = [ TABLE_ATTRIBUTES [ attr ] for attr in self . attributes if attr in TABLE_ATTRIBUTES ] , ) with open ( path , "w+" ) as file_h : file_h . write ( self . impl_content )