コード例 #1
0
ファイル: wiki_file_io.py プロジェクト: alyssaq/distil
def create_wiki_page(wiki_subdir_abspath, wiki_word):
  """Ensure the wiki-word directory and wiki-word file exist.
  
  Will also create the wiki-subdir if it doesn't already exist.
  """
  wiki_word_dir_abspath = os.path.join(wiki_subdir_abspath, wiki_word)
  os.makedirs(wiki_word_dir_abspath)

  wiki_fname_abspath = os.path.join(wiki_word_dir_abspath, wiki_word + constants.WIKI_FNAME_SUFFIX)
  filesystem_utils.create_empty_file(wiki_fname_abspath)
  repository.add(wiki_fname_abspath)
  repository.commit([wiki_fname_abspath],
      "created wiki page '%s'" % wiki_word)
コード例 #2
0
def create_wiki_page(wiki_subdir_abspath, wiki_word):
    """Ensure the wiki-word directory and wiki-word file exist.
  
  Will also create the wiki-subdir if it doesn't already exist.
  """
    wiki_word_dir_abspath = os.path.join(wiki_subdir_abspath, wiki_word)
    os.makedirs(wiki_word_dir_abspath)

    wiki_fname_abspath = os.path.join(wiki_word_dir_abspath,
                                      wiki_word + constants.WIKI_FNAME_SUFFIX)
    filesystem_utils.create_empty_file(wiki_fname_abspath)
    repository.add(wiki_fname_abspath)
    repository.commit([wiki_fname_abspath],
                      "created wiki page '%s'" % wiki_word)
コード例 #3
0
ファイル: wiki_file_io.py プロジェクト: alyssaq/distil
def ensure_file_added_to_repo_if_created(file_writing_func, fname_abspath, arg_to_write):
  """Does the file 'fname_abspath' already exist?
  
  If it doesn't already exist, then it will be created by 'file_writing_func',
  which means it will be a new file, not yet added into the repository.

  This function will ensure the file is added to the repository if the file is
  created by the file-writing function.
  """

  file_exists_before_write = os.path.exists(fname_abspath)
  file_writing_func(fname_abspath, arg_to_write)
  if not file_exists_before_write:
    # The file was just created.
    repository.add(fname_abspath)
コード例 #4
0
def ensure_file_added_to_repo_if_created(file_writing_func, fname_abspath,
                                         arg_to_write):
    """Does the file 'fname_abspath' already exist?
  
  If it doesn't already exist, then it will be created by 'file_writing_func',
  which means it will be a new file, not yet added into the repository.

  This function will ensure the file is added to the repository if the file is
  created by the file-writing function.
  """

    file_exists_before_write = os.path.exists(fname_abspath)
    file_writing_func(fname_abspath, arg_to_write)
    if not file_exists_before_write:
        # The file was just created.
        repository.add(fname_abspath)
コード例 #5
0
def write_topic_tags(fname_abspath, topic_tags):
    """Write the list of topic tags 'topic_tags' into the new topic tags file
  'fname_abspath'.

  The list of topic tags doesn't need to be sorted in advance, as it will be
  sorted in this function.
  """
    topic_tags.sort()

    # Does the file already exist?  This will determine whether we need to add it
    # to the repository before we can commit it.
    file_exists_before_write = os.path.exists(fname_abspath)

    # If there are no topic tags, we want to write an empty file rather than a
    # file containing only a newline.
    if not topic_tags:
        empty_file_contents(fname_abspath)
    else:
        open_file_write_one_per_line(fname_abspath, topic_tags)

    if not file_exists_before_write:
        repository.add(fname_abspath)
コード例 #6
0
ファイル: topic_tag_file_io.py プロジェクト: alyssaq/distil
def write_topic_tags(fname_abspath, topic_tags):
  """Write the list of topic tags 'topic_tags' into the new topic tags file
  'fname_abspath'.

  The list of topic tags doesn't need to be sorted in advance, as it will be
  sorted in this function.
  """
  topic_tags.sort()

  # Does the file already exist?  This will determine whether we need to add it
  # to the repository before we can commit it.
  file_exists_before_write = os.path.exists(fname_abspath)

  # If there are no topic tags, we want to write an empty file rather than a
  # file containing only a newline.
  if not topic_tags:
    empty_file_contents(fname_abspath)
  else:
    open_file_write_one_per_line(fname_abspath, topic_tags)

  if not file_exists_before_write:
    repository.add(fname_abspath)
コード例 #7
0
def write_topic_tag_index(fname_abspath, cite_keys, update_repository=True):
    """Write the list of cite-keys 'cite_keys' into the new topic tag index file
  'fname_abspath'.

  The list of cite-keys doesn't need to be sorted in advance, as it will be
  sorted in this function.
  """
    cite_keys.sort()

    # Does the file already exist?  This will determine whether we need to add it
    # to the repository before we can commit it.
    file_exists_before_write = os.path.exists(fname_abspath)

    # If there are no cite-keys, we want to delete the file from the directory
    # (since the file's presence will result in the presentation to the user
    # of an unused topic tag).
    if not cite_keys:
        # Delete the file, if it exists.
        if file_exists_before_write and update_repository:
            repository.remove(fname_abspath)
    else:
        open_file_write_one_per_line(fname_abspath, cite_keys)
        if not file_exists_before_write and update_repository:
            repository.add(fname_abspath)
コード例 #8
0
ファイル: topic_tag_file_io.py プロジェクト: alyssaq/distil
def write_topic_tag_index(fname_abspath, cite_keys, update_repository=True):
  """Write the list of cite-keys 'cite_keys' into the new topic tag index file
  'fname_abspath'.

  The list of cite-keys doesn't need to be sorted in advance, as it will be
  sorted in this function.
  """
  cite_keys.sort()

  # Does the file already exist?  This will determine whether we need to add it
  # to the repository before we can commit it.
  file_exists_before_write = os.path.exists(fname_abspath)

  # If there are no cite-keys, we want to delete the file from the directory
  # (since the file's presence will result in the presentation to the user
  # of an unused topic tag).
  if not cite_keys:
    # Delete the file, if it exists.
    if file_exists_before_write and update_repository:
      repository.remove(fname_abspath)
  else:
    open_file_write_one_per_line(fname_abspath, cite_keys)
    if not file_exists_before_write and update_repository:
      repository.add(fname_abspath)