Browse Source

Hopefully make it run in more places

tags/v0.1.3
Skylar Ittner 10 months ago
parent
commit
7b5c4c7b92
4 changed files with 128 additions and 69 deletions
  1. 94
    33
      .idea/workspace.xml
  2. 2
    3
      notepostcli/api.py
  3. 29
    28
      notepostcli/notepost.py
  4. 3
    5
      setup.py

+ 94
- 33
.idea/workspace.xml View File

@@ -3,11 +3,9 @@
<component name="ChangeListManager">
<list default="true" id="7e2ff7f2-75de-431f-9457-e0d648b65015" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/api.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/config.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/notepost.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/termcolors.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/notepostcli/api.py" beforeDir="false" afterPath="$PROJECT_DIR$/notepostcli/api.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/notepostcli/notepost.py" beforeDir="false" afterPath="$PROJECT_DIR$/notepostcli/notepost.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@@ -17,11 +15,47 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/setup.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="26" selection-start-line="26" selection-end-line="26" />
<state relative-caret-position="210">
<caret line="14" column="29" selection-start-line="14" selection-start-column="29" selection-end-line="14" selection-end-column="29" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/notepostcli/notepost.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="115" column="30" selection-start-line="115" selection-start-column="30" selection-end-line="115" selection-end-column="30" />
<folding>
<element signature="e#224#234#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/notepostcli/api.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="345">
<caret line="23" column="19" lean-forward="true" selection-start-line="23" selection-start-column="19" selection-end-line="23" selection-end-column="19" />
<folding>
<element signature="e#224#239#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/notepostcli/config.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="18" lean-forward="true" selection-start-line="18" selection-end-line="18" />
<folding>
<element signature="e#224#235#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
@@ -36,6 +70,12 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>i18n</find>
<find>valid</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
@@ -47,10 +87,12 @@
<option value="$PROJECT_DIR$/api.py" />
<option value="$PROJECT_DIR$/termcolors.py" />
<option value="$PROJECT_DIR$/notepost.py" />
<option value="$PROJECT_DIR$/notepostcli/api.py" />
<option value="$PROJECT_DIR$/notepostcli/notepost.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="4" />
<option name="width" value="1912" />
<option name="height" value="1038" />
@@ -61,7 +103,6 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@@ -69,6 +110,16 @@
<item name="NotePostCLI" type="b2602c69:ProjectViewProjectNode" />
<item name="NotePostCLI" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="NotePostCLI" type="b2602c69:ProjectViewProjectNode" />
<item name="NotePostCLI" type="462c0819:PsiDirectoryNode" />
<item name="notepostcli" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="NotePostCLI" type="b2602c69:ProjectViewProjectNode" />
<item name="NotePostCLI" type="462c0819:PsiDirectoryNode" />
<item name="share" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="NotePostCLI" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
@@ -77,9 +128,11 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$/bin" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RunDashboard">
@@ -136,9 +189,10 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="4" y="0" width="1912" height="1038" extended-state="0" />
<frame x="-4" y="0" width="1928" height="1046" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.18075491" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.17923036" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
@@ -167,44 +221,51 @@
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/note.class.py" />
<entry file="file://$PROJECT_DIR$/notepost.py">
<entry file="file://$PROJECT_DIR$/notepost.py" />
<entry file="file://$PROJECT_DIR$/termcolors.py" />
<entry file="file://$PROJECT_DIR$/api.py" />
<entry file="file://$PROJECT_DIR$/config.py" />
<entry file="file://$PROJECT_DIR$/setup.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2640">
<caret line="183" column="18" lean-forward="true" selection-start-line="183" selection-start-column="18" selection-end-line="183" selection-end-column="18" />
<folding>
<element signature="e#24#39#0" expanded="true" />
</folding>
<state relative-caret-position="210">
<caret line="14" column="29" selection-start-line="14" selection-start-column="29" selection-end-line="14" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/termcolors.py">
<entry file="file://$PROJECT_DIR$/notepostcli/api.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="285">
<caret line="19" column="22" selection-start-line="19" selection-start-column="22" selection-end-line="19" selection-end-column="22" />
<state relative-caret-position="345">
<caret line="23" column="19" lean-forward="true" selection-start-line="23" selection-start-column="19" selection-end-line="23" selection-end-column="19" />
<folding>
<element signature="e#224#239#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api.py">
<entry file="file://$PROJECT_DIR$/notepostcli/termcolors.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="11" column="56" selection-start-line="11" selection-start-column="56" selection-end-line="11" selection-end-column="56" />
<folding>
<element signature="e#24#35#0" expanded="true" />
</folding>
<state relative-caret-position="240">
<caret line="16" lean-forward="true" selection-start-line="16" selection-end-line="17" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config.py">
<entry file="file://$PROJECT_DIR$/notepostcli/config.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="60">
<caret line="4" column="9" selection-start-line="4" selection-start-column="9" selection-end-line="4" selection-end-column="9" />
<state relative-caret-position="270">
<caret line="18" lean-forward="true" selection-start-line="18" selection-end-line="18" />
<folding>
<element signature="e#224#235#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/setup.py">
<entry file="file://$PROJECT_DIR$/notepostcli/notepost.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="26" selection-start-line="26" selection-end-line="26" />
<state relative-caret-position="225">
<caret line="115" column="30" selection-start-line="115" selection-start-column="30" selection-end-line="115" selection-end-column="30" />
<folding>
<element signature="e#224#234#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

+ 2
- 3
notepostcli/api.py View File

@@ -4,7 +4,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import i18n
import requests

from config import getconfig
@@ -15,7 +14,7 @@ def do(action, data={}):
try:
r = requests.post(conf["url"] + "/api/" + action, data=data, auth=(conf["username"], conf["password"]))
except:
print(i18n.t("Could not connect to the server. Try again."))
print("Could not connect to the server. Try again.")
return

try:
@@ -24,4 +23,4 @@ def do(action, data={}):
raise Exception(resp["msg"])
return resp
except ValueError:
raise Exception(i18n.t("Invalid response from server."))
raise Exception("Invalid response from server.")

+ 29
- 28
notepostcli/notepost.py View File

@@ -12,9 +12,8 @@ except:
pass

import tempfile
import i18n
import validators
import requests
import re
import api
from config import *
from termcolors import *
@@ -30,36 +29,36 @@ def firstsetup(url="", username=""):
# Get URL
while True:
if url != "":
url = input(i18n.t("Server URL") + " (" + url + "): ") or url
url = input("Server URL (" + url + "): ") or url
else:
url = input(i18n.t("Server URL") + ": ")
if validators.url(url):
url = input("Server URL: ")
if re.compile("^(https?|ftp)://[^\s/$.?#].[^\s]*$").match(url):
break
else:
print(i18n.t("That doesn't look right, try again."))
print("That doesn't look right, try again.")
# Get username
while True:
if username != "":
username = input(i18n.t("Username") + " (" + username + "): ") or username
username = input("Username (" + username + "): ") or username
else:
username = input(i18n.t("Username") + ": ")
username = input("Username: ")
if username != "":
break
# Get password
while True:
password = getpass(i18n.t("Password") + ": ")
password = getpass("Password: ")
if password != "":
break

try:
r = requests.post(url + "/api/ping", auth=(username, password))
except:
print(i18n.t("Could not connect to the server. Try again."))
print("Could not connect to the server. Try again.")
firstsetup()
return

if r.status_code == 401:
print(i18n.t("Login incorrect, try again."))
print("Login incorrect, try again.")
firstsetup(url)
return

@@ -75,7 +74,7 @@ def firstsetup(url="", username=""):
saveconfig()
return
except ValueError:
print(i18n.t("Login incorrect, try again."))
print("Login incorrect, try again.")
firstsetup(url, username)
return

@@ -106,13 +105,15 @@ def editnote(note):
assert not os.path.exists(f.name)
note["content"] = text
clearscreen()
print(i18n.t("Saving..."))
print("Saving...")
savenote(note)
print(i18n.t("Note saved!"))
print("Note saved!")


def editmenu():
global notes
rows, columns = os.popen('stty size', 'r').read().split()
linelength = int(columns) - 10
clearscreen()
loadnotes()
i = 1
@@ -128,21 +129,21 @@ def editmenu():
if linecount > 5:
print("\n(" + str(len(note["content"].splitlines())) + " more lines" + ")", end='')
break
print("\n " + line[0:70].ljust(70), end='')
if len(line) > 70:
print("\n " + line[0:linelength].ljust(linelength), end='')
if len(line) > linelength:
print("...", end='')
linecount += 1
i += 1
resetcolor()
print("\n======================")
noteid = input(i18n.t("Note to edit (M for main menu): "))
noteid = input("Note to edit (M for main menu): ")
if noteid.upper() == "M":
clearscreen()
return
try:
editnote(notelist[noteid])
except KeyError:
print(i18n.t("Invalid selection."))
print("Invalid selection.")


def newnote():
@@ -159,23 +160,23 @@ def newnote():
assert not os.path.exists(f.name)
if text == "":
clearscreen()
print(i18n.t("Nothing to do."))
print("Nothing to do.")
return
print(i18n.t("Saving..."))
print("Saving...")
api.do("savenote", {
"text": text
})
print(i18n.t("Note created!"))
print("Note created!")


def mainmenu():
print("\n======================")
print(i18n.t("Main Menu"))
print("Main Menu")
print("======================")
print("E. " + i18n.t("View and edit notes"))
print("C. " + i18n.t("Create a new note"))
print("Q. " + i18n.t("Exit"))
option = input(i18n.t("Choose an option: ")).upper()
print("E. View and edit notes")
print("C. Create a new note")
print("Q. Exit")
option = input("Choose an option: ").upper()
clearscreen()
if option == "E":
editmenu()
@@ -184,13 +185,13 @@ def mainmenu():
elif option == "Q":
exit(0)
else:
print(i18n.t("Unrecognized selection, try again."))
print("Unrecognized selection, try again.")


def main():
print("NotePostCLI v0.1")
if not checkconfig():
print(i18n.t("No valid settings file found, running setup wizard."))
print("No valid settings file found, running setup wizard.")
firstsetup()
else:
loadconfig()

+ 3
- 5
setup.py View File

@@ -4,7 +4,7 @@
from setuptools import setup, find_packages
setup(
name="NotePostCLI",
version="0.1.2",
version="0.1.3",
packages=find_packages(),
install_requires=[
"appdirs>=1.4.3",
@@ -12,11 +12,9 @@ setup(
"chardet>=3.0",
"decorator>=4.1",
"idna>=2.6",
"python-i18n==0.3.5",
"requests>=2.18.0",
"six>=1.11.0",
"urllib3>=1.22",
"validators==0.12.3"
"six>=1.10.0",
"urllib3>=1.22"
],
entry_points = {
'console_scripts' : ['notepostcli = notepostcli.notepost:main']

Loading…
Cancel
Save