예제 #1
0
def _processUserEnvrionmentCommand(request, cmd_dict):
    """
  Processes commands that relate to the environment in which
  the user is executing.
  :param request: includes command structure in the GET
  :param cmd_dict: command informat extracted from the request
  :return: JSON structure or None if not a user environment command
  """
    command_result = None
    table = getTable(request)
    target = cmd_dict["target"]
    if target == 'Sheet':
        if cmd_dict['command'] == "Delete":
            current_file_path = _getTableFilepath(request)
            os.remove(current_file_path)
            command_result = _makeNewTable(request)
        elif cmd_dict['command'] == "ListSheetFiles":
            command_result = _listTableFiles()
        elif cmd_dict['command'] == "New":
            command_result = _makeNewTable(request)
        elif cmd_dict['command'] == "OpenSheetFile":
            filename = cmd_dict['args'][0]
            table_filepath = _createTableFilepath(filename)
            table = readObjectFromFile(table_filepath, verify=False)
            _setTableFilepath(request, table, cmd_dict['args'][0])
            command_result = _makeAjaxResponse("OK", True)
        elif cmd_dict['command'] == "SaveAs":
            table = getTable(request)
            _setTableFilepath(request,
                              table,
                              cmd_dict['args'][0],
                              verify=False)
            saveTable(request, table)  # Save table in the new path
            command_result = _makeAjaxResponse("OK", True)
    return command_result
예제 #2
0
def _processUserEnvrionmentCommand(request, cmd_dict):
  """
  Processes commands that relate to the environment in which
  the user is executing.
  :param request: includes command structure in the GET
  :param cmd_dict: command informat extracted from the request
  :return: JSON structure or None if not a user environment command
  """
  command_result = None
  table = getTable(request)
  target = cmd_dict["target"]
  if target == 'Table':
    if cmd_dict['command'] == "Delete":
      current_file_path = _getTableFilepath(request)
      os.remove(current_file_path)
      command_result = _makeNewTable(request)
    elif cmd_dict['command'] == "ListTableFiles":
      command_result = _listTableFiles()
    elif cmd_dict['command'] == "New":
      command_result = _makeNewTable(request)
    elif cmd_dict['command'] == "OpenTableFile":
      filename = cmd_dict['args'][0]
      table_filepath = _createTableFilepath(filename)
      table = readObjectFromFile(table_filepath, verify=False)
      _setTableFilepath(request, table, cmd_dict['args'][0])
      command_result = _makeAjaxResponse("OK", True)
    elif cmd_dict['command'] == "SaveAs":
      table = getTable(request)
      _setTableFilepath(request, table, cmd_dict['args'][0], 
          verify=False)
      saveTable(request, table)  # Save table in the new path
      command_result = _makeAjaxResponse("OK", True)
  return command_result
예제 #3
0
 def testRenderingListData(self):
   # set up the test table
   table_filepath = os.path.join(TEST_DIR, TESTFILE2)
   table = readObjectFromFile(table_filepath, verify=False)
   versioned_file = VersionedFile(table_filepath, TEST_DIR, 0)
   table.setVersionedFile(versioned_file)
   html = table.render()
예제 #4
0
 def testRenderingListData(self):
   # set up the test table
   if IGNORE_TEST:
     return
   table_filepath = os.path.join(TEST_DIR, TESTFILE2)
   table = readObjectFromFile(table_filepath, verify=False)
   versioned_file = VersionedFile(table_filepath, TEST_DIR, 0)
   table.setVersionedFile(versioned_file)
   html = table.render()
예제 #5
0
def getTable(request):
    """
 Returns the table if found
  """
    table_file_path = _getTableFilepath(request)
    if table_file_path is None:
        return None
    else:
        return readObjectFromFile(table_file_path, verify=False)
예제 #6
0
def getTable(request):
  """
 Returns the table if found
  """
  table_file_path = _getTableFilepath(request)
  if table_file_path is None:
    return None
  else:
    return readObjectFromFile(table_file_path, verify=False)
예제 #7
0
 def create(self):
   """
   Creates Table file and the table
   """
   if os.path.exists(self._full_path):
     self.table = api_util.readObjectFromFile(self._full_path)
     self.table.setFilepath(self._full_path)  # Set before write
   else:
     self.table = DTTable(self._table_name)
     self.table.setFilepath(self._full_path)  # Set before write
     api_util.writeObjectToFile(self.table) 
예제 #8
0
 def create(self):
     """
 Creates Table file and the table
 """
     if os.path.exists(self._full_path):
         self.table = api_util.readObjectFromFile(self._full_path)
         self.table.setFilepath(self._full_path)  # Set before write
     else:
         self.table = DTTable(self._table_name)
         self.table.setFilepath(self._full_path)  # Set before write
         api_util.writeObjectToFile(self.table)
예제 #9
0
def _makeNewTable(request):
  """
  Creates a new table
  :param request: includes command structure in the GET
  :return: ajax response
  """
  empty_table_file = _createTableFilepath(EMPTY_TABLE_FILE)
  table = readObjectFromFile(empty_table_file)
  _setTableFilepath(request, table, 
      settings.SCISHEETS_DEFAULT_TABLEFILE,
      verify=False)
  saveTable(request, table)  # Save table in the new path
  return _makeAjaxResponse("OK", True)
예제 #10
0
def _makeNewTable(request):
    """
  Creates a new table
  :param request: includes command structure in the GET
  :return: ajax response
  """
    empty_table_file = _createTableFilepath(EMPTY_TABLE_FILE)
    table = readObjectFromFile(empty_table_file)
    _setTableFilepath(request,
                      table,
                      settings.SCISHEETS_DEFAULT_TABLEFILE,
                      verify=False)
    saveTable(request, table)  # Save table in the new path
    return _makeAjaxResponse("OK", True)
예제 #11
0
def migrate(path):
  """
  :param str path: filepath
  Creates an sci file with an sci extension
  """
  ext = path[-3:]
  if ext.lower() != 'pcl':
    raise ValueError("%s is not a pcl file" % path)
  try:
    an_object = readObjectFromFile(path)
  except Exception as e:
    import pdb; pdb.set_trace()
    return
  json_str = serialize(an_object)
  new_path = "%s.sci" % path[:-4]
  with open(new_path, "wb") as fh:
    fh.write(json_str)
예제 #12
0
 def testSpecificCases(self):
   """
   Inputs to test cases are stored in pcl files.
   """
   if IGNORE_TEST:
     return
   files = ["test_dt_table_1.scish"]
   # Tests are functions that take result as an argument and return a bool
   tests = [ (lambda r: r[1]['Col_1'] == `0.5`)]
   iterations = range(len(files))
   for idx in iterations:
      path = os.path.join(CUR_DIR, files[idx])
      inputs = api_util.readObjectFromFile(path)
      column_names = inputs[0]
      data = inputs[1]
      result = dt.makeJSData(data)
      self.assertEqual(len(result), len(data[0]))
예제 #13
0
 def testSpecificCases(self):
   """
   Inputs to test cases are stored in pcl files.
   """
   files = ["test_dt_table_1.scish"]
   # Tests are functions that take result as an argument and return a bool
   tests = [ (lambda r: r[1]['Col_1'] == `0.5`)]
   iterations = range(len(files))
   for idx in iterations:
      path = os.path.join(CUR_DIR, files[idx])
      inputs = api_util.readObjectFromFile(path)
      column_names = inputs[0]
      data = inputs[1]
      result = dt.makeJSON(column_names, data)
      cleaned_result = result.replace("`", "'")
      result_list = ast.literal_eval(cleaned_result)
      test = tests[idx]
      self.assertTrue(test(result_list))
예제 #14
0
def migrate(path):
    """
  :param str path: filepath
  Creates an sci file with an sci extension
  """
    ext = path[-3:]
    if ext.lower() != 'pcl':
        raise ValueError("%s is not a pcl file" % path)
    try:
        an_object = readObjectFromFile(path)
    except Exception as e:
        import pdb
        pdb.set_trace()
        return
    json_str = serialize(an_object)
    new_path = "%s.sci" % path[:-4]
    with open(new_path, "wb") as fh:
        fh.write(json_str)
예제 #15
0
 def _getTableFromResponse(self, response):
     table_filepath = response.client.session[sv.TABLE_FILE_KEY]
     return readObjectFromFile(table_filepath)
예제 #16
0
 def setUp(self):
     self.table = readObjectFromFile(TEST_TABLE_FILE, verify=False)
     self.api = api.APIFormulas(self.table)
 def _getTableFromResponse(self, response):
   table_filepath = response.client.session[sv.TABLE_FILE_KEY]
   return readObjectFromFile(table_filepath)
 def setUp(self):
   self.table = readObjectFromFile(TEST_TABLE_FILE, verify=False)
   self.api = api.APIFormulas(self.table)