Guest User

Untitled

a guest
Feb 20th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4.  
  5. Note = id + content + tags + created + modified + public_url
  6. Share a note = publish to gist.
  7. Public need github account
  8. """
  9.  
  10. import json
  11. import os.path
  12.  
  13. import click
  14.  
  15.  
  16. RC_FILES = [
  17. './.zetanoterc',
  18. '~/.zetanoterc',
  19. '/usr/local/etc/zetanote/zetanoterc',
  20. '/etc/zetanote/zenoterc',
  21. ]
  22.  
  23.  
  24. def read_rc():
  25. """Resolve one RC file and parse it.
  26.  
  27. RC file must be in JSON format.
  28.  
  29. The order of search files are:
  30.  
  31. * `./.zetanoterc`
  32. * `~/.zetanoterc`
  33. * '/usr/local/etc/zetanote/zetanoterc`
  34. * `/etc/zetanote/zenoterc`
  35. """
  36. for rc_file in RC_FILES:
  37. if os.path.exists(rc_file):
  38. with open(rc_file) as f:
  39. return json.load(f)
  40. return {}
  41.  
  42.  
  43. @click.group()
  44. @click.pass_context
  45. def zetanote(ctx):
  46. """Zetanote - Organizing notes in less pain."""
  47. ctx.RC = read_rc()
  48.  
  49.  
  50. @zetanote.command()
  51. @click.pass_context
  52. def ls(ctx):
  53. """List all notes."""
  54. pass
  55.  
  56.  
  57. @zetanote.command()
  58. @click.pass_context
  59. def rm(ctx):
  60. """Remove notes."""
  61.  
  62.  
  63. @zetanote.command()
  64. @click.pass_context
  65. def tree(ctx):
  66. """List notes as tree.
  67.  
  68. Example Output::
  69.  
  70. .
  71. ├── DeicW | Hello World
  72. | ├── EckwA | Sub Page 1
  73. | ├── EciWL | Sub Page 2
  74. ...
  75.  
  76. """
  77.  
  78.  
  79. @zetanote.command()
  80. @click.pass_context
  81. def add(ctx):
  82. """Create a new note from input, and then output the link.
  83.  
  84. This link is similar to `zetanote://XdoaQ`
  85. """
  86.  
  87.  
  88. @zetanote.command()
  89. @click.pass_context
  90. def edit(ctx):
  91. """Edit an existing note."""
  92.  
  93.  
  94. @zetanote.command()
  95. @click.pass_context
  96. def open(ctx):
  97. """Open a note in $EDITOR, and create it if note doesn't exist.
  98. """
  99.  
  100.  
  101. if __name__ == '__main__':
  102. zetanote()
Add Comment
Please, Sign In to add comment