From 8c4f6e37479002818bcfe7381cd4e4b47fd2d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 26 Apr 2019 01:32:07 +0200 Subject: Start splitting nix environment to smaller files --- pkgs/terminal-velocity/default.nix | 33 ++++ pkgs/terminal-velocity/fix_build.patch | 21 +++ pkgs/terminal-velocity/python3_support.patch | 215 ++++++++++++++++++++++++++ pkgs/terminal-velocity/sort_found_notes.patch | 73 +++++++++ 4 files changed, 342 insertions(+) create mode 100644 pkgs/terminal-velocity/default.nix create mode 100644 pkgs/terminal-velocity/fix_build.patch create mode 100644 pkgs/terminal-velocity/python3_support.patch create mode 100644 pkgs/terminal-velocity/sort_found_notes.patch (limited to 'pkgs/terminal-velocity') diff --git a/pkgs/terminal-velocity/default.nix b/pkgs/terminal-velocity/default.nix new file mode 100644 index 0000000..9e79dee --- /dev/null +++ b/pkgs/terminal-velocity/default.nix @@ -0,0 +1,33 @@ +{ python36Packages }: +with python36Packages; +buildPythonApplication rec { + pname = "terminal-velocity-git"; + version = "0.2.0"; + src = fetchPypi { + inherit pname version; + sha256 = "13yrkcmvh5h5fwnai61sbmqkrjyisz08n62pq0ada2lyyqf7g6b9"; + }; + + patches = [ + ./sort_found_notes.patch + ./python3_support.patch + # FIXME: update this patch when version changes + ./fix_build.patch + ]; + + propagatedBuildInputs = [ + chardet + urwid + (sh.overridePythonAttrs { doCheck = false; }) + pyyaml + ]; + buildInputs = [ + m2r + (restructuredtext_lint.overridePythonAttrs { doCheck = false; }) + pygments + ]; + + postInstall = '' + rm $out/bin/terminal_velocity + ''; +} diff --git a/pkgs/terminal-velocity/fix_build.patch b/pkgs/terminal-velocity/fix_build.patch new file mode 100644 index 0000000..b08e0c4 --- /dev/null +++ b/pkgs/terminal-velocity/fix_build.patch @@ -0,0 +1,21 @@ +commit a64bf3d58f6ba7f5fa72fe5b89a3973cac0c1a99 +Author: Ismaël Bouya +Date: Sat Mar 9 20:13:52 2019 +0100 + + Remove mister_bump dependency + +diff --git a/setup.py b/setup.py +index 84a99e9..a783dff 100644 +--- a/setup.py ++++ b/setup.py +@@ -1,7 +1,9 @@ + from setuptools import setup + from m2r import parse_from_file + import restructuredtext_lint +-from mister_bump import bump ++ ++def bump(): ++ return "0.2.0" + + # Parser README.md into reStructuredText format + rst_readme = parse_from_file('README.md') diff --git a/pkgs/terminal-velocity/python3_support.patch b/pkgs/terminal-velocity/python3_support.patch new file mode 100644 index 0000000..bd4aec7 --- /dev/null +++ b/pkgs/terminal-velocity/python3_support.patch @@ -0,0 +1,215 @@ +commit 6ca19964b9e8a7866fd7e21a3dac9ccd35f0d434 +Author: Ismaël Bouya +Date: Sat Mar 9 20:13:18 2019 +0100 + + Add python3 support + +diff --git a/terminal_velocity/notebook.py b/terminal_velocity/notebook.py +index b6226dc..11f76de 100644 +--- a/terminal_velocity/notebook.py ++++ b/terminal_velocity/notebook.py +@@ -60,51 +60,6 @@ import sys + import chardet + + +-def unicode_or_bust(raw_text): +- """Return the given raw text data decoded to unicode. +- +- If the text cannot be decoded, return None. +- +- """ +- encodings = ["utf-8"] +- for encoding in (sys.getfilesystemencoding(), sys.getdefaultencoding()): +- # I would use a set for this, but they don't maintain order. +- if encoding not in encodings: +- encodings.append(encoding) +- +- for encoding in encodings: +- if encoding: # getfilesystemencoding() may return None +- try: +- decoded = unicode(raw_text, encoding=encoding) +- return decoded +- except UnicodeDecodeError: +- pass +- +- # If none of those guesses worked, let chardet have a go. +- encoding = chardet.detect(raw_text)["encoding"] +- if encoding and encoding not in encodings: +- try: +- decoded = unicode(raw_text, encoding=encoding) +- logger.debug("File decoded with chardet, encoding was {0}".format( +- encoding)) +- return decoded +- except UnicodeDecodeError: +- pass +- except LookupError: +- pass +- +- # I've heard that decoding with cp1252 never fails, so try that last. +- try: +- decoded = unicode(raw_text, encoding="cp1252") +- logger.debug("File decoded with encoding cp1252") +- return decoded +- except UnicodeDecodeError: +- pass +- +- # If nothing worked then give up. +- return None +- +- + class Error(Exception): + """Base class for exceptions in this module.""" + pass +@@ -192,12 +147,12 @@ class PlainTextNote(object): + # subdirs) if they don't exist. + directory = os.path.split(self.abspath)[0] + if not os.path.isdir(directory): +- logger.debug(u"'{0} doesn't exist, creating it".format(directory)) ++ logger.debug("'{0} doesn't exist, creating it".format(directory)) + try: + os.makedirs(directory) + except os.error as e: + raise NewNoteError( +- u"{0} could not be created: {1}".format(directory, e)) ++ "{0} could not be created: {1}".format(directory, e)) + + # Create an empty file if the file doesn't exist. + open(self.abspath, 'a') +@@ -217,11 +172,11 @@ class PlainTextNote(object): + + @property + def contents(self): +- contents = unicode_or_bust(open(self.abspath, "r").read()) ++ contents = open(self.abspath, "rb").read().decode(errors='ignore') + if contents is None: + logger.error( +- u"Could not decode file contents: {0}".format(self.abspath)) +- return u"" ++ "Could not decode file contents: {0}".format(self.abspath)) ++ return "" + else: + return contents + +@@ -322,12 +277,12 @@ class PlainTextNoteBook(object): + + # Create notebook_dir if it doesn't exist. + if not os.path.isdir(self.path): +- logger.debug(u"'{0} doesn't exist, creating it".format(self.path)) ++ logger.debug("'{0} doesn't exist, creating it".format(self.path)) + try: + os.makedirs(self.path) + except os.error as e: + raise NewNoteBookError( +- u"{0} could not be created: {1}".format(self.path, e)) ++ "{0} could not be created: {1}".format(self.path, e)) + else: + # TODO: Check that self.path is a directory, if not raise. + pass +@@ -358,13 +313,12 @@ class PlainTextNoteBook(object): + abspath = os.path.join(root, filename) + relpath = os.path.relpath(abspath, self.path) + relpath, ext = os.path.splitext(relpath) +- unicode_relpath = unicode_or_bust(relpath) + if relpath is None: + # The filename could not be decoded. + logger.error( + "Could not decode filename: {0}".format(relpath)) + else: +- self.add_new(title=unicode_relpath, extension=ext) ++ self.add_new(title=relpath, extension=ext) + + @property + def path(self): +@@ -418,7 +372,7 @@ class PlainTextNoteBook(object): + for note in self._notes: + if note.title == title and note.extension == extension: + raise NoteAlreadyExistsError( +- u"Note already in NoteBook: {0}".format(note.title)) ++ "Note already in NoteBook: {0}".format(note.title)) + + # Ok, add the note. + note = PlainTextNote(title, self, extension) +diff --git a/terminal_velocity/terminal_velocity.py b/terminal_velocity/terminal_velocity.py +index 5f0e213..9234bea 100755 +--- a/terminal_velocity/terminal_velocity.py ++++ b/terminal_velocity/terminal_velocity.py +@@ -1,7 +1,7 @@ +-#!/usr/bin/env python2 ++#!/usr/bin/env python3 + """A fast note-taking app for the UNIX terminal""" + from __future__ import print_function +-import ConfigParser ++import configparser + import argparse + import os + import logging +@@ -9,9 +9,9 @@ import logging.handlers + import sys + + #import terminal_velocity.urwid_ui as urwid_ui +-import urwid_ui ++from . import urwid_ui + +-from git import get_git_project_config, git_project_is_configured, fetch_changes, push_changes ++from .git import get_git_project_config, git_project_is_configured, fetch_changes, push_changes + + + def startup(): +@@ -37,7 +37,7 @@ def main(): + + # Parse the config file. + config_file = os.path.abspath(os.path.expanduser(args.config)) +- config = ConfigParser.SafeConfigParser() ++ config = configparser.ConfigParser() + config.read(config_file) + defaults = dict(config.items('DEFAULT')) + +diff --git a/terminal_velocity/urwid_ui.py b/terminal_velocity/urwid_ui.py +index caebcb9..89bab35 100644 +--- a/terminal_velocity/urwid_ui.py ++++ b/terminal_velocity/urwid_ui.py +@@ -10,7 +10,7 @@ import logging + logger = logging.getLogger(__name__) + + import urwid +-import notebook ++from . import notebook + + + palette = [ +@@ -27,8 +27,6 @@ def system(cmd, loop): + + loop.screen.stop() + +- cmd = u"{0}".format(cmd) +- cmd = cmd.encode("utf-8") # FIXME: Correct encoding? + safe_cmd = shlex.split(cmd) + + logger.debug("System command: {0}".format(safe_cmd)) +@@ -114,7 +112,7 @@ class AutocompleteWidget(urwid.Edit): + + # When search bar is empty show placeholder text. + if not self.edit_text and not self.autocomplete_text: +- placeholder_text = u"Find or Create" ++ placeholder_text = "Find or Create" + return (placeholder_text, + [("placeholder", len(placeholder_text))]) + +@@ -186,7 +184,7 @@ class NoteFilterListBox(urwid.ListBox): + + def render(self, size, focus=False): + if len(self.list_walker) == 0: +- placeholder = placeholder_text(u"No matching notes, press Enter " ++ placeholder = placeholder_text("No matching notes, press Enter " + "to create a new note") + return placeholder.render(size) + return super(NoteFilterListBox, self).render(size, self.fake_focus) +@@ -399,7 +397,7 @@ class MainFrame(urwid.Frame): + # If the user has no notes yet show some placeholder text, otherwise + # show the note list. + if len(self.notebook) == 0: +- self.body = placeholder_text(u"You have no notes yet, to create " ++ self.body = placeholder_text("You have no notes yet, to create " + "a note type a note title then press Enter") + else: + self.body = urwid.Padding(self.list_box, left=1, right=1) diff --git a/pkgs/terminal-velocity/sort_found_notes.patch b/pkgs/terminal-velocity/sort_found_notes.patch new file mode 100644 index 0000000..2bc563c --- /dev/null +++ b/pkgs/terminal-velocity/sort_found_notes.patch @@ -0,0 +1,73 @@ +commit 0f9df37046e58c8963aff93c649e5d3dbf2202bd +Author: Ismaël Bouya +Date: Sat Mar 9 20:11:46 2019 +0100 + + Add sorting option + +diff --git a/terminal_velocity/terminal_velocity.py b/terminal_velocity/terminal_velocity.py +index a53eda3..5f0e213 100755 +--- a/terminal_velocity/terminal_velocity.py ++++ b/terminal_velocity/terminal_velocity.py +@@ -90,6 +90,10 @@ the default default will be used""" + default=defaults.get("log_file", "~/.tvlog"), + help="the file to log to (default: %(default)s)") + ++ parser.add_argument("-s", "--sort", dest="sort", action="store", ++ default=defaults.get("sort", "date"), ++ help="the note sorting rules. Possible values: date, title (default: %(default)s)") ++ + parser.add_argument("-p", "--print-config", dest="print_config", + action="store_true", default=False, + help="print your configuration settings then exit") +@@ -138,7 +142,7 @@ the default default will be used""" + try: + urwid_ui.launch(notes_dir=args.notes_dir, editor=args.editor, + extension=args.extension, extensions=args.extensions, +- exclude=args.exclude) ++ exclude=args.exclude, sort=args.sort) + except KeyboardInterrupt: + # Run the shutdown hook + shutdown() +diff --git a/terminal_velocity/urwid_ui.py b/terminal_velocity/urwid_ui.py +index 34cf4f6..caebcb9 100644 +--- a/terminal_velocity/urwid_ui.py ++++ b/terminal_velocity/urwid_ui.py +@@ -237,11 +237,12 @@ class NoteFilterListBox(urwid.ListBox): + class MainFrame(urwid.Frame): + """The topmost urwid widget.""" + +- def __init__(self, notes_dir, editor, extension, extensions, exclude=None): ++ def __init__(self, notes_dir, editor, extension, extensions, exclude=None, sort="date"): + + self.editor = editor + self.notebook = notebook.PlainTextNoteBook(notes_dir, extension, + extensions, exclude=exclude) ++ self.sort = sort + + # Don't filter the note list when the text in the search box changes. + self.suppress_filter = False +@@ -408,7 +409,10 @@ class MainFrame(urwid.Frame): + + # Sort the notes. + # TODO: Support different sort orderings. +- matching_notes.sort(key=lambda x: x.mtime, reverse=True) ++ if self.sort == "title": ++ matching_notes.sort(key=lambda x: x.title) ++ else: ++ matching_notes.sort(key=lambda x: x.mtime, reverse=True) + + # Tell the list box to show only the matching notes. + self.list_box.filter(matching_notes) +@@ -433,10 +437,10 @@ class MainFrame(urwid.Frame): + self.selected_note = note + + +-def launch(notes_dir, editor, extension, extensions, exclude=None): ++def launch(notes_dir, editor, extension, extensions, exclude=None, sort="date"): + """Launch the user interface.""" + +- frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude) ++ frame = MainFrame(notes_dir, editor, extension, extensions, exclude=exclude, sort=sort) + loop = urwid.MainLoop(frame, palette) + frame.loop = loop + loop.run() -- cgit v1.2.3