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 --- default.nix | 85 +-------- hooks/tiv_builder.sh | 8 - patches/terminal_velocity_fix_build.patch | 21 --- patches/terminal_velocity_python3_support.patch | 215 ----------------------- patches/terminal_velocity_sort_found_notes.patch | 73 -------- pkgs/mtop/default.nix | 24 +++ pkgs/note/default.nix | 18 ++ 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 ++++++++ pkgs/tiv/default.nix | 19 ++ pkgs/tiv/tiv_builder.sh | 8 + 13 files changed, 415 insertions(+), 398 deletions(-) delete mode 100644 hooks/tiv_builder.sh delete mode 100644 patches/terminal_velocity_fix_build.patch delete mode 100644 patches/terminal_velocity_python3_support.patch delete mode 100644 patches/terminal_velocity_sort_found_notes.patch create mode 100644 pkgs/mtop/default.nix create mode 100644 pkgs/note/default.nix 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 create mode 100644 pkgs/tiv/default.nix create mode 100644 pkgs/tiv/tiv_builder.sh diff --git a/default.nix b/default.nix index 51ebcc2..38d7e0b 100644 --- a/default.nix +++ b/default.nix @@ -74,87 +74,10 @@ let }; }; - buildPerlPackage = perlPackages.buildPerlPackage; - mypkgs.note = buildPerlPackage rec { - name = "note-1.3.26"; - src = fetchurl { - url = "mirror://cpan/authors/id/T/TL/TLINDEN/${name}.tar.gz"; - sha256 = "1h645rnb5vpms48fcyzvp7cwwcbf9k5xq49w2bpniyzzgk2brjrq"; - }; - outputs = ["out" "man"]; - propagatedBuildInputs = [ perlPackages.YAML ]; - meta = with stdenv.lib; { - description = "A perl script for maintaining notes"; - homepage = http://www.daemon.de/NOTE; - license = licenses.gpl3; - maintainers = with maintainers; [ { name = "T.v.Dein"; email = "tlinden@cpan.org"; } ]; - platforms = platforms.unix; - }; - }; - - mypkgs.terminal-velocity = with python36Packages; buildPythonApplication rec { - pname = "terminal-velocity-git"; - version = "0.2.0"; - - patches = [ - ./patches/terminal_velocity_sort_found_notes.patch - ./patches/terminal_velocity_python3_support.patch - # FIXME: update this patch when version changes - ./patches/terminal_velocity_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 - ''; - src = fetchPypi { - inherit pname version; - sha256 = "13yrkcmvh5h5fwnai61sbmqkrjyisz08n62pq0ada2lyyqf7g6b9"; - }; - }; - - mypkgs.mtop = buildPerlPackage rec { - name = "mtop-${version}"; - version = "0.6.6"; - src = fetchurl { - url = "http://downloads.sourceforge.net/project/mtop/mtop/v${version}/mtop-${version}.tar.gz"; - sha256 = "0x0x5300b1j9i0xxk8rsrki0pspyzj2vylhzv8qg3l6j26aw0zrf"; - }; - outputs = ["out"]; - buildInputs = [ perlPackages.DBI perlPackages.DBDmysql perlPackages.Curses ]; - - postInstall = '' - cd "$out" - preConfigure || true - ''; - meta = with stdenv.lib; { - description = "MySQL top (monitor and examine slow queries)"; - homepage = http://mtop.sourceforge.net/; - license = licenses.gpl3; - maintainers = with maintainers; [ { name = "Marc Prewitt"; email = "mprewitt@chelsea.net"; } ]; - platforms = platforms.unix; - }; - }; - - mypkgs.tiv = buildPerlPackage rec { - name = "tiv-${version}"; - version = "2015"; - src = fetchurl { - url = "http://xyne.archlinux.ca/projects/tiv/src/tiv-${version}.tar.xz"; - sha256 = "1vq073v7z7vmcd57lhs4rf4jasji69cpjgkz4dykp94a77p1qq90"; - }; - outputs = ["out"]; - buildInputs = [ perlPackages.PerlMagick ]; - perlPreHookScript = ./hooks/tiv_builder.sh; - perlPreHook = '' - source ${perlPreHookScript} - ''; - installPhase = '' - install -Dm755 tiv "$out/bin/tiv" - ''; - }; + mypkgs.mtop = callPackage ./pkgs/mtop {}; + mypkgs.note = callPackage ./pkgs/note {}; + mypkgs.terminal-velocity = callPackage ./pkgs/terminal-velocity {}; + mypkgs.tiv = callPackage ./pkgs/tiv {}; mypkgs.cnagios = stdenv.mkDerivation (fetchedGithub ./fetched/cnagios.json // rec { configureFlags = [ diff --git a/hooks/tiv_builder.sh b/hooks/tiv_builder.sh deleted file mode 100644 index ea16682..0000000 --- a/hooks/tiv_builder.sh +++ /dev/null @@ -1,8 +0,0 @@ -orig=$(declare -f preConfigure) -new_name="preConfigure2 ${orig#preConfigure}" -eval "$new_name" - -preConfigure() { - preConfigure2 || true -} - diff --git a/patches/terminal_velocity_fix_build.patch b/patches/terminal_velocity_fix_build.patch deleted file mode 100644 index b08e0c4..0000000 --- a/patches/terminal_velocity_fix_build.patch +++ /dev/null @@ -1,21 +0,0 @@ -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/patches/terminal_velocity_python3_support.patch b/patches/terminal_velocity_python3_support.patch deleted file mode 100644 index bd4aec7..0000000 --- a/patches/terminal_velocity_python3_support.patch +++ /dev/null @@ -1,215 +0,0 @@ -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/patches/terminal_velocity_sort_found_notes.patch b/patches/terminal_velocity_sort_found_notes.patch deleted file mode 100644 index 2bc563c..0000000 --- a/patches/terminal_velocity_sort_found_notes.patch +++ /dev/null @@ -1,73 +0,0 @@ -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() diff --git a/pkgs/mtop/default.nix b/pkgs/mtop/default.nix new file mode 100644 index 0000000..4a89430 --- /dev/null +++ b/pkgs/mtop/default.nix @@ -0,0 +1,24 @@ +{ buildPerlPackage, fetchurl, perlPackages, lib }: +buildPerlPackage rec { + name = "mtop-${version}"; + version = "0.6.6"; + src = fetchurl { + url = "http://downloads.sourceforge.net/project/mtop/mtop/v${version}/mtop-${version}.tar.gz"; + sha256 = "0x0x5300b1j9i0xxk8rsrki0pspyzj2vylhzv8qg3l6j26aw0zrf"; + }; + outputs = ["out"]; + buildInputs = with perlPackages; [ DBI DBDmysql Curses ]; + + postInstall = '' + cd "$out" + preConfigure || true + ''; + + meta = with lib; { + description = "MySQL top (monitor and examine slow queries)"; + homepage = http://mtop.sourceforge.net/; + license = licenses.gpl3; + maintainers = with maintainers; [ { name = "Marc Prewitt"; email = "mprewitt@chelsea.net"; } ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/note/default.nix b/pkgs/note/default.nix new file mode 100644 index 0000000..0c422bc --- /dev/null +++ b/pkgs/note/default.nix @@ -0,0 +1,18 @@ +{ lib, buildPerlPackage, fetchurl, perlPackages }: +buildPerlPackage rec { + name = "note-1.3.26"; + src = fetchurl { + url = "mirror://cpan/authors/id/T/TL/TLINDEN/${name}.tar.gz"; + sha256 = "1h645rnb5vpms48fcyzvp7cwwcbf9k5xq49w2bpniyzzgk2brjrq"; + }; + outputs = ["out" "man"]; + propagatedBuildInputs = with perlPackages; [ YAML ]; + + meta = with lib; { + description = "A perl script for maintaining notes"; + homepage = http://www.daemon.de/NOTE; + license = licenses.gpl3; + maintainers = with maintainers; [ { name = "T.v.Dein"; email = "tlinden@cpan.org"; } ]; + platforms = platforms.unix; + }; +} 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() diff --git a/pkgs/tiv/default.nix b/pkgs/tiv/default.nix new file mode 100644 index 0000000..c03aabe --- /dev/null +++ b/pkgs/tiv/default.nix @@ -0,0 +1,19 @@ +{ buildPerlPackage, fetchurl, perlPackages }: +buildPerlPackage rec { + name = "tiv-${version}"; + version = "2015"; + src = fetchurl { + url = "http://xyne.archlinux.ca/projects/tiv/src/tiv-${version}.tar.xz"; + sha256 = "1vq073v7z7vmcd57lhs4rf4jasji69cpjgkz4dykp94a77p1qq90"; + }; + + outputs = ["out"]; + buildInputs = with perlPackages; [ PerlMagick ]; + perlPreHookScript = ./tiv_builder.sh; + perlPreHook = '' + source $perlPreHookScript + ''; + installPhase = '' + install -Dm755 tiv "$out/bin/tiv" + ''; +} diff --git a/pkgs/tiv/tiv_builder.sh b/pkgs/tiv/tiv_builder.sh new file mode 100644 index 0000000..ea16682 --- /dev/null +++ b/pkgs/tiv/tiv_builder.sh @@ -0,0 +1,8 @@ +orig=$(declare -f preConfigure) +new_name="preConfigure2 ${orig#preConfigure}" +eval "$new_name" + +preConfigure() { + preConfigure2 || true +} + -- cgit v1.2.3