示例#1
0
文件: tgt.py 项目: cloudbase/maas
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)
示例#2
0
文件: tgt.py 项目: cloudbase/maas
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)
示例#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)
示例#4
0
文件: tgt.py 项目: cloudbase/maas
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)
示例#5
0
文件: tgt.py 项目: cloudbase/maas
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)))
示例#6
0
文件: tgt.py 项目: cloudbase/maas
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)
示例#7
0
文件: tgt.py 项目: cloudbase/maas
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)))
示例#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')))
示例#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')))
示例#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))
示例#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))