メイン処理
質問の生成、folder生成など。

BoipQuestionCreator

Boipのクエスト生成クラス

__init__(self, target_path=None) special

initialize.

Parameters:

Name Type Description Default
target_path str

BoipSetを追加で検索する用のパス。DefaultsはNone

None
Source code in boip/app.py
def __init__(self, target_path=None):
    """initialize.

    Args:
        target_path (str, optional): BoipSetを追加で検索する用のパス。DefaultsはNone
    """
    self.boip_set_list = BoipSetList(target_path)
    self.title = None
    self.question_answer = None
    self.duplicate_folder_path = None

create_question(self)

質問を作成する

Source code in boip/app.py
def create_question(self):
    """質問を作成する  
    """
    self.__create_template_selector()
    self.__create_multi_question()
    self.__create_folder_question()
    self.__replace_file()

各実行クラスモジュール

BaseReader

ベースの読み込みクラス

__metaclass__

Metaclass for defining Abstract Base Classes (ABCs).

Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as 'virtual subclasses' -- these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won't show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).

__instancecheck__(cls, instance) special

Override for isinstance(instance, cls).

Source code in boip/operation.py
def __instancecheck__(cls, instance):
    """Override for isinstance(instance, cls)."""
    return _abc_instancecheck(cls, instance)

__new__(mcls, name, bases, namespace, **kwargs) special staticmethod

Create and return a new object. See help(type) for accurate signature.

Source code in boip/operation.py
def __new__(mcls, name, bases, namespace, **kwargs):
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
    _abc_init(cls)
    return cls

__subclasscheck__(cls, subclass) special

Override for issubclass(subclass, cls).

Source code in boip/operation.py
def __subclasscheck__(cls, subclass):
    """Override for issubclass(subclass, cls)."""
    return _abc_subclasscheck(cls, subclass)

register(cls, subclass)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

Source code in boip/operation.py
def register(cls, subclass):
    """Register a virtual subclass of an ABC.

    Returns the subclass, to allow usage as a class decorator.
    """
    return _abc_register(cls, subclass)

__init__(self, path) special

initialize.

Parameters:

Name Type Description Default
path str

対象のフォルダパス

required
Source code in boip/operation.py
def __init__(self, path):
    """initialize.

    Args:
        path (str): 対象のフォルダパス
    """
    self.read_path = path

get_read_data(self)

読み込んだデータを返す

Source code in boip/operation.py
@ abstractmethod
def get_read_data(self):
    # type: () -> None
    """読み込んだデータを返す
    """
    pass

BoipSetList

質問とtemplateFolderのセットクラス

__init__(self, additional_path=None) special

initialize.

Parameters:

Name Type Description Default
search_path str

boip_setを検索したいルートフォルダパス. Defaults to PRESET_FOLDER.

required
Source code in boip/operation.py
def __init__(self, additional_path=None):
    """initialize.

    Args:
        search_path (str, optional): boip_setを検索したいルートフォルダパス. Defaults to PRESET_FOLDER.
    """
    self.__boip_set_list = self.__get_boip_set_list(additional_path)

duplicate_template_folder(self, dis_folder, src_folder_name)

TemplateFolderを複製する

Parameters:

Name Type Description Default
dis_folder str

複製元のフォルダパス

required
src_folder_name str

複製先のフォルダパス

required
Source code in boip/operation.py
def duplicate_template_folder(self, dis_folder, src_folder_name):
    # type: (str, str) -> str
    """TemplateFolderを複製する

    Args:
        dis_folder (str): 複製元のフォルダパス
        src_folder_name (str): 複製先のフォルダパス
    """
    current_directory = os.getcwd()

    target_folder = os.path.join(current_directory, src_folder_name)

    shutil.copytree(dis_folder, target_folder)
    return target_folder

get_title_list(self)

タイトルリストを取得する

Returns:

Type Description
list

タイトルリスト

Source code in boip/operation.py
def get_title_list(self):
    # type: () -> list
    """タイトルリストを取得する

    Returns:
        list: タイトルリスト
    """
    title_list = []
    for template_set in self.__boip_set_list:
        title_list.append(template_set.title)
    return title_list

select_convert_extensions(self, target_title)

titleから該当のconvert_extensionsを取得する

Parameters:

Name Type Description Default
target_title str

対象のtitle名

required

Returns:

Type Description
dict

{dist extensins: src extensins}

Source code in boip/operation.py
def select_convert_extensions(self, target_title):
    # type: (str) -> {str, str}
    """titleから該当のconvert_extensionsを取得する

    Args:
        target_title (str): 対象のtitle名

    Returns:
        dict: {dist extensins: src extensins}
    """
    for template_set in self.__boip_set_list:
        if target_title == template_set.title:
            return template_set.convert_extensions

select_questions(self, target_title)

titleから該当のquestionsを取得する

Parameters:

Name Type Description Default
target_title str

検索したboip.yamlから選択したtile名

required

Returns:

Type Description
list

[{"name": "質問の答えを格納する変数名", "message": "質問"}]

Source code in boip/operation.py
def select_questions(self, target_title):
    # type: (str) -> list[{str: str}]
    """titleから該当のquestionsを取得する

    Args:
        target_title (str): 検索したboip.yamlから選択したtile名

    Returns:
        list: [{"name": "質問の答えを格納する変数名", "message": "質問"}]
    """
    for template_set in self.__boip_set_list:
        if target_title == template_set.title:
            return template_set.questions

select_template_path(self, target_title)

titleから該当のTemplateFolderPathを取得する

Parameters:

Name Type Description Default
target_title str

setting_file内のtitle名

required

Returns:

Type Description
str

TemplateFolderPath

Source code in boip/operation.py
def select_template_path(self, target_title):
    # type: (str) -> str
    """titleから該当のTemplateFolderPathを取得する

    Args:
        target_title (str): setting_file内のtitle名

    Returns:
        str: TemplateFolderPath
    """
    for template_set in self.__boip_set_list:
        if target_title == template_set.title:
            return template_set.template_path

FileFormatter

ファイルフォーマットクラス

__init__(self, formatter_data) special

initialize.

Parameters:

Name Type Description Default
formatter_data dict

フォーマットに使用するdict。

required
Source code in boip/operation.py
def __init__(self, formatter_data):
    """initialize.

    Args:
        formatter_data (dict): フォーマットに使用するdict。
    """
    self.__formatter_data = formatter_data

replace_file(self, target_file, replace_extension)

ファイルを上書きする

Parameters:

Name Type Description Default
target_file [type]

[description]

required
insert_text [type]

[description]

required
after_extension [type]

[description]

required
Source code in boip/operation.py
def replace_file(self, target_file, replace_extension):
    """ファイルを上書きする

    Args:
        target_file ([type]): [description]
        insert_text ([type]): [description]
        after_extension ([type]): [description]
    """
    target_string = self.__load_string_from_file(target_file)
    after_string = self.__format_data(target_string)
    self.__edit_file(target_file, after_string)
    self.__change_extension(target_file, replace_extension)

FolderFormatter

フォルダの置き換え実行クラス

__init__(self, template_folder_path, convert_extension_data, formatter_data) special

initialize.

Parameters:

Name Type Description Default
template_folder_path str

テンプレートフォルダパス

required
convert_extension_data dict

{変更前の拡張子: 変更後の拡張子}

required
formatter_data list

置き換えに使うフォーマットデータ{"変数名": "置き換え後の文字"}

required
Source code in boip/operation.py
def __init__(self, template_folder_path, convert_extension_data, formatter_data):
    """initialize.

    Args:
        template_folder_path (str): テンプレートフォルダパス
        convert_extension_data (dict): {変更前の拡張子: 変更後の拡張子}
        formatter_data (list): 置き換えに使うフォーマットデータ{"変数名": "置き換え後の文字"}
    """
    super(FolderFormatter, self).__init__(formatter_data)
    self.__path = template_folder_path
    self.__convert_extension_data = convert_extension_data

replace_files(self)

複数ファイルを上書きする

Source code in boip/operation.py
def replace_files(self):
    """複数ファイルを上書きする
    """
    for before_extension, after_extension in self.__convert_extension_data.items():
        target_files = self.__search_extension_file(self.__path, before_extension)
        for target_file in target_files:
            super(FolderFormatter, self).replace_file(target_file, after_extension)

SettingData

SettingDataデータ構造

convert_extensions property readonly

拡張子変更リスト

Returns:

Type Description
dict

{変更前: 変更後}

questions property readonly

質問リスト

Returns:

Type Description
list

質問リスト

template_path property readonly

テンプレートフォルダのパス

Returns:

Type Description
str

フォルダパス

title property readonly

boip.yaml内のtitle

Returns:

Type Description
str

title

YamlFileReader

YamlFile用のReader

get_read_data(self)

読み込んだデータを返す

Returns:

Type Description
dict

yaml data.

Source code in boip/operation.py
def get_read_data(self):
    """読み込んだデータを返す

    Returns:
        dict: yaml data.
    """
    with open(self.read_path) as f:
        yaml_data = yaml.load(f, Loader=yaml.FullLoader)
        return yaml_data