forked from jrnl-org/jrnl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
180 lines (152 loc) · 6.76 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
jrnl is a simple journal application for your command line. Journals are stored as human readable plain text files - you can put them into a Dropbox folder for instant syncinc and you can be assured that your journal will still be readable in 2050, when all your fancy iPad journal applications will long be forgotten.
Optionally, your journal can be encrypted using 256-bit AES.
Why keep a journal?
```````````````````
Journals aren't only for 13-year old girls and people who have too much time on their summer vacation. A journal helps you to keep track of the things you get done and how you did them. Your imagination may be limitless, but your memory isn't. For personal use, make it a good habit to write at least 20 words a day. Just to reflect what made this day special, why you haven't wasted it. For professional use, consider a text-based journal to be the perfect complement to your GTD todo list - a documentation of what and how you've done it.
In a Nutshell
`````````````
to make a new entry, just type
::
jrnl yesterday: Called in sick. Used the time to clean the house and spent 4h on writing my book.
and hit return. yesterday` will be interpreted as a timestamp. Everything until the first sentence mark (.?!) will be interpreted as the title, the rest as the body. In your journal file, the result will look like this:
::
2012-03-29 09:00 Called in sick.
Used the time to clean the house and spent 4h on writing my book.
If you just call jrnl you will be prompted to compose your entry - but you can also configure jrnl to use your external editor.
Links
`````
* `website & documentation <http://maebert.github.com/jrnl>`_
* `GitHub Repo <https://github.com/maebert/jrnl>`_
"""
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import os
import sys
import re
try:
import readline
readline_available = True
except ImportError:
readline_available = False
base_dir = os.path.dirname(os.path.abspath(__file__))
def get_version(filename="jrnl/__init__.py"):
with open(os.path.join(base_dir, filename)) as initfile:
for line in initfile.readlines():
m = re.match("__version__ *= *['\"](.*)['\"]", line)
if m:
return m.group(1)
def get_changelog(filename="CHANGELOG.md"):
changelog = {}
current_version = None
with open(os.path.join(base_dir, filename)) as changelog_file:
for line in changelog_file.readlines():
if line.startswith("* __"):
parts = line.strip("* ").split(" ", 1)
if len(parts) == 2:
current_version, changes = parts[0].strip("_\n"), parts[1]
changelog[current_version] = [changes.strip()]
else:
current_version = parts[0].strip("_\n")
changelog[current_version] = []
elif line.strip() and current_version and not line.startswith("#"):
changelog[current_version].append(line.strip(" *\n"))
return changelog
def dist_pypi():
os.system("python setup.py sdist upload")
sys.exit()
def dist_github():
"""Creates a release on the maebert/jrnl repository on github"""
import requests
import keyring
import getpass
version = get_version()
version_tuple = version.split(".")
changes_since_last_version = ["* __{}__: {}".format(key, "\n".join(changes)) for key, changes in get_changelog().items() if key.startswith("{}.{}".format(*version_tuple))]
changes_since_last_version = "\n".join(sorted(changes_since_last_version, reverse=True))
payload = {
"tag_name": version,
"target_commitish": "master",
"name": version,
"body": "Changes in Version {}.{}: \n\n{}".format(version_tuple[0], version_tuple[1], changes_since_last_version)
}
print("Preparing release {}...".format(version))
username = keyring.get_password("github", "__default_user") or raw_input("Github username: ")
password = keyring.get_password("github", username) or getpass.getpass()
otp = raw_input("One Time Token: ")
response = requests.post("https://api.github.com/repos/maebert/jrnl/releases", headers={"X-GitHub-OTP": otp}, json=payload, auth=(username, password))
if response.status_code in (403, 404):
print("Authentication error.")
else:
keyring.set_password("github", "__default_user", username)
keyring.set_password("github", username, password)
if response.status_code > 299:
if "message" in response.json():
print("Error: {}".format(response.json()['message']))
for error_dict in response.json().get('errors', []):
print("*", error_dict)
else:
print("Unkown error")
print(response.text)
else:
print("Release created.")
sys.exit()
if sys.argv[-1] == 'publish':
dist_pypi()
if sys.argv[-1] == 'github_release':
dist_github()
conditional_dependencies = {
"pyreadline>=2.0": not readline_available and "win32" in sys.platform,
"readline>=6.2": not readline_available and "win32" not in sys.platform,
"colorama>=0.2.5": "win32" in sys.platform,
"argparse>=1.1.0": sys.version.startswith("2.6"),
"python-dateutil==1.5": sys.version.startswith("2."),
"python-dateutil>=2.2": sys.version.startswith("3."),
}
setup(
name = "jrnl",
version = get_version(),
description = "A command line journal application that stores your journal in a plain text file",
packages = ['jrnl'],
install_requires = [
"parsedatetime>=1.2",
"pytz>=2013b",
"six>=1.6.1",
"tzlocal>=1.1",
"keyring>=3.3",
] + [p for p, cond in conditional_dependencies.items() if cond],
extras_require = {
"encrypted": "pycrypto>=2.6"
},
long_description=__doc__,
entry_points={
"console_scripts": [
"jrnl = jrnl:run",
]
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Office/Business :: News/Diary",
"Topic :: Text Processing"
],
# metadata for upload to PyPI
author = "Manuel Ebert",
author_email = "[email protected]",
license="LICENSE",
keywords = "journal todo todo.txt jrnl".split(),
url = "http://www.jrnl.sh",
)