def _create_temp_dirpath(temp_dirpath):
  if os.path.isdir(temp_dirpath):
    shutil.rmtree(temp_dirpath)
  elif os.path.isfile(temp_dirpath):
    os.remove(temp_dirpath)
    
  _path_dirs.make_dirs(temp_dirpath)
def _create_temp_dirpath(temp_dirpath):
    if os.path.isdir(temp_dirpath):
        shutil.rmtree(temp_dirpath)
    elif os.path.isfile(temp_dirpath):
        os.remove(temp_dirpath)

    _path_dirs.make_dirs(temp_dirpath)
def _move_files_with_filters_to_temporary_location(
        repository_dirpath, relative_filepaths_with_git_filters,
        dirpath_with_original_files_with_git_filters):
    for relative_filepath in relative_filepaths_with_git_filters:
        src_filepath = os.path.join(repository_dirpath, relative_filepath)
        dest_filepath = os.path.join(
            dirpath_with_original_files_with_git_filters, relative_filepath)

        _path_dirs.make_dirs(os.path.dirname(dest_filepath))
        shutil.copy2(src_filepath, dest_filepath)
        os.remove(src_filepath)
def _move_files_with_filters_to_temporary_location(
      repository_dirpath,
      relative_filepaths_with_git_filters,
      dirpath_with_original_files_with_git_filters):
  for relative_filepath in relative_filepaths_with_git_filters:
    src_filepath = os.path.join(repository_dirpath, relative_filepath)
    dest_filepath = os.path.join(
      dirpath_with_original_files_with_git_filters, relative_filepath)
    
    _path_dirs.make_dirs(os.path.dirname(dest_filepath))
    shutil.copy2(src_filepath, dest_filepath)
    os.remove(src_filepath)
def make_installers(input_dirpath=PLUGINS_DIRPATH,
                    installer_dirpath=OUTPUT_DIRPATH_DEFAULT,
                    force_if_dirty=False,
                    installers=None,
                    generate_docs=True):
    _path_dirs.make_dirs(installer_dirpath)

    temp_repo_files_dirpath = tempfile.mkdtemp()

    relative_filepaths_with_git_filters = (_prepare_repo_files_for_packaging(
        input_dirpath, temp_repo_files_dirpath, force_if_dirty))

    _generate_translation_files(pg.config.LOCALE_DIRPATH)

    temp_dirpath = TEMP_INPUT_DIRPATH

    _create_temp_dirpath(temp_dirpath)

    if generate_docs:
        _create_user_docs(os.path.join(temp_dirpath, pg.config.PLUGIN_NAME))

    input_filepaths = _get_filtered_filepaths(input_dirpath,
                                              INCLUDE_LIST_FILEPATH)
    user_docs_filepaths = _get_filtered_filepaths(temp_dirpath,
                                                  INCLUDE_LIST_FILEPATH)

    relative_filepaths = (
        _get_relative_filepaths(input_filepaths, input_dirpath) +
        _get_relative_filepaths(user_docs_filepaths, temp_dirpath))

    temp_filepaths = [
        os.path.join(temp_dirpath, relative_filepath)
        for relative_filepath in relative_filepaths
    ]

    _copy_files_to_temp_filepaths(input_filepaths, temp_filepaths)

    _set_permissions(temp_dirpath, 0o755)

    _create_installers(installer_dirpath, temp_dirpath, temp_filepaths,
                       relative_filepaths, installers)

    _restore_repo_files(temp_repo_files_dirpath, input_dirpath,
                        relative_filepaths_with_git_filters)

    shutil.rmtree(temp_dirpath)
    shutil.rmtree(temp_repo_files_dirpath)
    _remove_pot_files(pg.config.LOCALE_DIRPATH)
def make_installers(
      input_dirpath=PLUGINS_DIRPATH,
      installer_dirpath=OUTPUT_DIRPATH_DEFAULT,
      force_if_dirty=False,
      installers=None,
      generate_docs=True):
  _path_dirs.make_dirs(installer_dirpath)
  
  temp_repo_files_dirpath = tempfile.mkdtemp()
  
  relative_filepaths_with_git_filters = (
    _prepare_repo_files_for_packaging(
      input_dirpath, temp_repo_files_dirpath, force_if_dirty))
  
  _generate_translation_files(pg.config.LOCALE_DIRPATH)

  temp_dirpath = TEMP_INPUT_DIRPATH
  
  _create_temp_dirpath(temp_dirpath)
  
  if generate_docs:
    _create_user_docs(os.path.join(temp_dirpath, pg.config.PLUGIN_NAME))
  
  input_filepaths = _get_filtered_filepaths(input_dirpath, INCLUDE_LIST_FILEPATH)
  user_docs_filepaths = _get_filtered_filepaths(temp_dirpath, INCLUDE_LIST_FILEPATH)
  
  relative_filepaths = (
    _get_relative_filepaths(input_filepaths, input_dirpath)
    + _get_relative_filepaths(user_docs_filepaths, temp_dirpath))
  
  temp_filepaths = [
    os.path.join(temp_dirpath, relative_filepath)
    for relative_filepath in relative_filepaths]
  
  _copy_files_to_temp_filepaths(input_filepaths, temp_filepaths)
  
  _set_permissions(temp_dirpath, 0o755)
  
  _create_installers(
    installer_dirpath, temp_dirpath, temp_filepaths, relative_filepaths, installers)
  
  _restore_repo_files(
    temp_repo_files_dirpath, input_dirpath, relative_filepaths_with_git_filters)
  
  shutil.rmtree(temp_dirpath)
  shutil.rmtree(temp_repo_files_dirpath)
  _remove_pot_files(pg.config.LOCALE_DIRPATH)
def _copy_files_to_temp_filepaths(filepaths, temp_filepaths):
  for src_filepath, temp_filepath in zip(filepaths, temp_filepaths):
    dirpath = os.path.dirname(temp_filepath)
    if not os.path.exists(dirpath):
      _path_dirs.make_dirs(dirpath)
    shutil.copy2(src_filepath, temp_filepath)
def _copy_files_to_temp_filepaths(filepaths, temp_filepaths):
    for src_filepath, temp_filepath in zip(filepaths, temp_filepaths):
        dirpath = os.path.dirname(temp_filepath)
        if not os.path.exists(dirpath):
            _path_dirs.make_dirs(dirpath)
        shutil.copy2(src_filepath, temp_filepath)