示例#1
0
def edit_file(file):
    """Opens an editor in which the user edits the given file.

    It invokes the editor program stored in the ``EDITOR`` environment
    variable. If ``EDITOR`` is undefined or empty, it invokes the default
    editor on the system using the :func:`default_editor` function.

    **Type:** |EditFileFun|
    """

    old_content = hkutils.file_to_string(file, return_none=True)

    editor = os.getenv('EDITOR')

    # if EDITOR is not set, get the default editor
    if editor is None or editor == '':
        editor = default_editor()

    # if not even the default is set, print an error message
    if editor is None:
        hklib.log(
            'Cannot determine the default editor based on the operating\n'
            'system. Please set the EDITOR environment variable to the editor\n'
            'you want to use or set hkshell.options.callback.edit_file to\n'
            'call your editor of choice.')
        return False

    subprocess.call(editor.split() + [file])
    return hkutils.file_to_string(file, return_none=True) != old_content
示例#2
0
    def file_content(self, filename):
        """Returns the content of the given file in the HTML directory.

        **Returns:** str
        """

        long_filename = os.path.join(self._html_dir, filename)
        return hkutils.file_to_string(long_filename)
示例#3
0
def edit_files(files):
    """DEPRECATED. Opens an editor in which the user edits the given files.

    Please use :func:`hkshell.edit_files` instead.

    It invokes the editor program stored in the ``EDITOR`` environment
    variable. If ``EDITOR`` is undefined or empty, it invokes the default
    editor on the system using the :func:`default_editor` function.

    **Type:** |EditFileFun|
    """

    old_content = {}
    for file in files:
        old_content[file] = hkutils.file_to_string(file, return_none=True)

    editor = os.getenv('HEAPKEEPER_EDITOR')

    # if HEAPKEEPER_EDITOR is not set, get EDITOR
    if editor is None or editor == '':
        editor = os.getenv('EDITOR')

    # if EDITOR is not set, get the default editor
    if editor is None or editor == '':
        editor = default_editor()

    # if not even the default is set, print an error message
    if editor is None:
        hkutils.log(
           'Cannot determine the default editor based on the operating\n'
           'system. Please set the EDITOR environment variable to the editor\n'
           'you want to use or set hkshell.options.callback.edit_files to\n'
           'call your editor of choice.')
        return False

    try:
        editor = editor_to_editor_list(editor)
    except IncorrectEditorException:
        hkutils.log(
            'The editor variable is incorrect:\n' +
            editor +
            'Please set the EDITOR environment variable to the editor\n'
            'you want to use or set hkshell.options.callback.edit_files to\n'
            'call your editor of choice.')
        return False

    subprocess.call(editor + files)

    def did_file_change(file):
        new_content = hkutils.file_to_string(file, return_none=True)
        return old_content[file] != new_content

    changed_files = filter(did_file_change, files)
    return changed_files
示例#4
0
    def GET(self, name):
        """Serves a HTTP GET request.

        **Argument:**

        - `name` (unicode) -- The name of the URL that was requested.

        **Returns:** str
        """

        filename = hkutils.uutf8(name)
        return hkutils.file_to_string(filename)
示例#5
0
def trailingline_tester():
    # Current directory should be: Heapkeeper

    # Finding bad files
    bad_files = []
    for file in git_source_files():
        file_content = hkutils.file_to_string(file)
        if re.search(r"[\n\r][\n\r]$", file_content):
            bad_files.append(file)

    # Examining the results
    bad_files_2 = [file + "\n" for file in bad_files]
    return (bad_files == [], "".join(bad_files_2))
示例#6
0
 def editor(files):
     [file] = files
     real_content = hkutils.file_to_string(file)
     self.assertEqual(expected_content, real_content)
     return [file]
示例#7
0
def get_content(file):
    return hkutils.file_to_string(file, return_none=True)
示例#8
0
 def did_file_change(file):
     new_content = hkutils.file_to_string(file, return_none=True)
     return old_content[file] != new_content