Example #1
0
    def test_file_write_convert(self):
        data = {"test": "test"}
        tests = {
            fops.JSON: '{\n    "test": "test"\n}',
            fops.KV: 'test=test',
            fops.XML:
            '<?xml version="1.0" encoding="utf-8"?>\n<test>test</test>',
            fops.YAML: 'test: test'
        }
        for key, value in tests.items():
            path = os.path.join(tempfile.gettempdir(),
                                "tempFile.{0!s}".format(key))
            args = fops.file_write_convert_defaults(key)
            fops.file_write_convert(path, key, data, dumper_args=args)

            try:
                self.assertTrue(os.path.isfile(path))
            except Exception:
                _cleanup(path)
                raise

            got = fops.file_read(path, strip=True)
            _cleanup(path)

            self.assertEqual(value, got, msg=key)
def _save_container_file(container_name: str, file_path: str,
                         out_dict: dict) -> None:
    LOGGER.debug("Saving configuration for '%s'", container_name)
    for i in {
            'group', 'image_password', 'image_username', 'image_build_path',
            'net', 'network', 'restart', 'tag'
    }:
        if out_dict[i] is None:
            out_dict[i] = ''
    fops.file_write_convert(file_path, 'YAML', out_dict)
Example #3
0
def _main_process_mp3_dir_finish(nfo_data: dict) -> None:
    """Copies cover.jpg to folder.jpg, and saves album.nfo

    Args:
        nfo_data: dictionary of NFO data to save to album.nfo
    """
    LOGGER.info("   ** cover.jpg -> folder.jpg")
    shutil.copyfile("cover.jpg", 'folder.jpg')

    LOGGER.info("   ** album.nfo")
    fops.file_write_convert(__ALBUM_NFO, fops.XML, nfo_data)
    def dump(self) -> str:
        """Dumps the configuration for this container to a file in the
           current working directory.

        Returns:
            Path to written file.
        """
        cur_path = os.path.abspath(os.path.curdir)
        yaml_file = os.path.join(cur_path, "{0!s}.yaml".format(self.info.name))
        fops.file_write_convert(yaml_file, 'YAML', self.info.to_dict())

        LOGGER.debug("Wrote current config to: %s", yaml_file)

        return yaml_file
def setup() -> None:
    """Run the setup routine for file_create."""
    new_defaults = deepcopy(DEFAULTS)
    new_defaults['copyright_holder'] = input("What is the name of the default copyright holder? : ")

    done = False
    while not done:
        new_author = input("What is the name of the author? : ")
        new_email = input("What is the email address for this author? : ")
        if not new_author or not new_email:
            LOGGER.error("you must provide both a name and an email address for the author.")
            continue
        new_defaults['author'] = "{0!s} <{1!s}>".format(new_author, new_email)
        done = True

    os.makedirs(CONFIG_DIR_PATH, 0o700, exist_ok=True)
    fops.file_write_convert(CONFIG_FILE_PATH, fops.YAML, new_defaults)
Example #6
0
def copy_info(orig_info: str, new_info: str, no_info: str, new_base: str,
              pages: list) -> list:
    """Copies the ComicInfo.xml file over, fixing pages entries.

    Args:
        orig_info: Full path to the original ComicInfo.xml.
        new_info: Full path to the new ComicInfo.xml.
        no_info: Full path to NoComicInfo file if no ComicInfo.xml is found.
        new_base: Full path to the directory containing comic book files.
        pages: List of pages for the new comic book.
    """
    if not os.path.isfile(orig_info):
        Path(no_info).touch()
        return pages

    comic_info_data = fops.file_read_convert(orig_info, fops.XML, default=True)
    if comic_info_data.get('ComicInfo'):
        comic_info_pages_page = []
        page_count = 0
        for page in sorted(pages):
            path = os.path.join(new_base, page)
            image = Image.open(fr'{path}')
            page_info = OrderedDict()
            page_info['@Image'] = str(page_count)
            page_info['@ImageWidth'] = str(image.width)
            page_info['@ImageHeight'] = str(image.height)
            image.close()
            comic_info_pages_page.append(page_info)
            page_count += 1

        comic_info_pages_page[0]['@Type'] = 'FrontCover'
        comic_info_data['ComicInfo']['Pages'] = OrderedDict()
        comic_info_data['ComicInfo']['Pages']['Page'] = comic_info_pages_page

    fops.file_write_convert(new_info, fops.XML, comic_info_data)

    return pages + [COMIC_INFO_XML]
Example #7
0
 def save(self) -> None:
     """Save group information to file."""
     LOGGER.debug('Saving groups information.')
     fops.file_write_convert(self.__config, 'YAML', self.__groups.to_dict())