Пример #1
0
def readObjectFromFile(filepath, verify=False):
  """
  Get the object from the file
  :param str filepath: full path to file
  :param bool verify: checks the file path if the
      object has a getFilepath method
  :return object:
  :raises ValueError: Checks that the file path is set
  Notes: Handles legacy of accessing PCL files, which
         is mostly in tests.
  """
  if ut.getFileExtension(filepath).lower() == 'pcl':
    adj_filepath = ut.changeFileExtension(filepath,
        settings.SCISHEETS_EXT)
  else:
    adj_filepath = filepath
  with open(adj_filepath, "r") as fh:
    json_str = fh.read()
    new_object = deserialize(json_str)
  if 'getFilepath' in dir(new_object):
    if verify and new_object.getFilepath() != adj_filepath:
      if new_object.getFilepath() == filepath:
        new_object.setFilepath(adj_filepath)
      else:
        raise ValueError("File path is incorrect or missing.")
  return new_object
Пример #2
0
 def getSerializationDict(self, class_variable):
   """
   :param str class_variable: key to use for the class name
   :return dict: dictionary encoding the Table object and its columns
   """
   serialization_dict = {}
   serialization_dict[class_variable] = str(self.__class__)
   filepath = self.getFilepath()
   if self.getFilepath() is not None:
     if ut.getFileExtension(self.getFilepath()) != settings.SCISHEETS_EXT:
       filepath = ut.changeFileExtension(self.getFilepath(), 
           settings.SCISHEETS_EXT)
   more_dict = {
       "_name": self.getName(is_global_name=False),
       "_prologue_formula": self.getPrologue().getFormula(),
       "_epilogue_formula": self.getEpilogue().getFormula(),
       "_is_evaluate_formulas": self.getIsEvaluateFormulas(),
       "_filepath": filepath,
       }
   serialization_dict.update(more_dict)
   _children = []
   for child in self.getChildren():
     if not Table.isNameColumn(child):
       _children.append(child.getSerializationDict(class_variable))
   serialization_dict["_children"] = _children
   return serialization_dict
Пример #3
0
def _createTableFilepath(file_name):
  """
  Input: file_name - name of file without extension
  Output: file_path - full path for file
  """
  path =  os.path.join(settings.SCISHEETS_USER_TBLDIR, file_name)
  adj_path = ut.changeFileExtension(path, settings.SCISHEETS_EXT)
  return adj_path