Esempio n. 1
0
def write_info_file(target_dir, target_name, release, label, serial, arch):
    """Write the `info` file based on the given parameters."""
    text = INFO_TEMPLATE.format(
        release=release, label=label, serial=serial, arch=arch,
        name=target_name)
    info_file = os.path.join(target_dir, 'info')
    write_text_file(info_file, text)
Esempio n. 2
0
def write_info_file(target_dir, target_name, release, label, serial, arch):
    """Write the `info` file based on the given parameters."""
    text = INFO_TEMPLATE.format(release=release,
                                label=label,
                                serial=serial,
                                arch=arch,
                                name=target_name)
    info_file = os.path.join(target_dir, 'info')
    write_text_file(info_file, text)
Esempio n. 3
0
    def test_creates_real_fresh_directory(self):
        stored_text = factory.getRandomString()
        filename = factory.make_name('test-file')
        with tempdir() as directory:
            self.assertThat(directory, DirExists())
            write_text_file(os.path.join(directory, filename), stored_text)
            retrieved_text = read_text_file(os.path.join(directory, filename))
            files = os.listdir(directory)

        self.assertEqual(stored_text, retrieved_text)
        self.assertEqual([filename], files)
Esempio n. 4
0
def write_conf(path, target_name, image):
    """Write a `tgt.conf` file."""
    text = TGT_CONF_TEMPLATE.format(target_name=target_name, image=image)
    write_text_file(path, text)
Esempio n. 5
0
def set_up_data_dir(data_dir):
    """Create a data directory and its configuration directory."""
    ensure_dir(tgt_conf_d(data_dir))
    write_text_file(
        os.path.join(data_dir, 'tgt.conf'),
        DATA_DIR_TGT_CONF_TEMPLATE.format(path=tgt_conf_d(data_dir)))
Esempio n. 6
0
def write_conf(path, target_name, image):
    """Write a `tgt.conf` file."""
    text = TGT_CONF_TEMPLATE.format(target_name=target_name, image=image)
    write_text_file(path, text)
Esempio n. 7
0
def set_up_data_dir(data_dir):
    """Create a data directory and its configuration directory."""
    ensure_dir(tgt_conf_d(data_dir))
    write_text_file(
        os.path.join(data_dir, 'tgt.conf'),
        DATA_DIR_TGT_CONF_TEMPLATE.format(path=tgt_conf_d(data_dir)))
Esempio n. 8
0
 def test_uses_given_encoding(self):
     path = self.make_file()
     # Test input: "registered trademark" (ringed R) symbol.
     text = '\xae'
     write_text_file(path, text, encoding='utf-16')
     self.assertThat(path, FileContains(text.encode('utf-16')))
Esempio n. 9
0
 def test_defaults_to_utf8(self):
     path = self.make_file()
     # Test input: "registered trademark" (ringed R) symbol.
     text = '\xae'
     write_text_file(path, text)
     self.assertThat(path, FileContains(text.encode('utf-8')))
Esempio n. 10
0
 def test_overwrites_file(self):
     path = self.make_file(contents="original text")
     text = factory.getRandomString()
     write_text_file(path, text)
     self.assertThat(path, FileContains(text))
Esempio n. 11
0
 def test_creates_file(self):
     path = os.path.join(self.make_dir(), factory.make_name('text'))
     text = factory.getRandomString()
     write_text_file(path, text)
     self.assertThat(path, FileContains(text))