def __init__(self, **kwargs):
     # Simply invokes the behavior of the superclass, but sets the filename keyword argument if it's not already set.
     if 'filename' in kwargs:
         super(MagicsFileHandler, self).__init__(**kwargs)
     else:
         magics_home_path = get_magics_home_path()
         logs_folder_name = "logs"
         log_file_name = "log_{}.log".format(get_instance_id())
         directory = FileSystemReaderWriter(join_paths(magics_home_path, logs_folder_name))
         directory.ensure_path_exists()
         super(MagicsFileHandler, self).__init__(filename=join_paths(directory.path, log_file_name), **kwargs)
def test_read():
    path = "test"
    if os.path.isfile(path):
        os.remove(path)

    expected_lines = ["a\n", "b"]
    rw = FileSystemReaderWriter(path)
    with open("test", "w") as f:
        f.writelines(expected_lines)

    read_lines = rw.read_lines()
    assert expected_lines == read_lines

    os.remove(path)
Beispiel #3
0
 def __init__(self, **kwargs):
     # Simply invokes the behavior of the superclass, but sets the filename keyword argument if it's not already set.
     if 'filename' in kwargs:
         super(MagicsFileHandler, self).__init__(**kwargs)
     else:
         magics_home_path = get_magics_home_path()
         logs_folder_name = "logs"
         log_file_name = "log_{}.log".format(get_instance_id())
         directory = FileSystemReaderWriter(
             join_paths(magics_home_path, logs_folder_name))
         directory.ensure_path_exists()
         super(MagicsFileHandler,
               self).__init__(filename=join_paths(directory.path,
                                                  log_file_name),
                              **kwargs)
def test_write_non_existent_file():
    path = "test"
    if os.path.isfile(path):
        os.remove(path)

    expected_line = "hi"

    rw = FileSystemReaderWriter(path)
    rw.overwrite_with_line(expected_line)

    with open("test", "r") as f:
        lines = f.readlines()
        assert len(lines) == 1
        assert lines[0] == expected_line

    os.remove(path)
Beispiel #5
0
    def __init__(self, ipython_display, serialize_path=None):
        self.logger = Log("SparkController")
        self.ipython_display = ipython_display

        if serialize_path is not None:
            serializer = ClientManagerStateSerializer(
                FileSystemReaderWriter(serialize_path))
            self.client_manager = ClientManager(serializer)
        else:
            self.client_manager = ClientManager()