Skip to content

Commit

Permalink
Merge pull request #62 from RedAtman/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RedAtman authored Aug 1, 2024
2 parents b07a2ae + 91fb163 commit 542b767
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 267 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ test/* export-ignore

# Exclude github files from the package
.github/ export-ignore
.gitignore export-ignore

# Exclude project files from the package
pyproject.toml export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
package-metadata.json
sublime_api.py
# *.sublime-settings
*.sublime-settings.example
Expand Down Expand Up @@ -28,7 +29,7 @@ build/
develop-eggs/
dist/
eggs/
lib/
# lib/
lib64/
parts/
sdist/
Expand Down
81 changes: 68 additions & 13 deletions _config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,55 @@
]


_SETTINGS_TEMPLATE = """
// Simplenote Settings - User
// First time use, To configure your Simplenote account username and password in the settings file.
// After that, save the settings file, Then wait for the sync.
{
// --------------------------------
// Credentials:
// --------------------------------
"username": ""
,"password": ""
// --------------------------------
// Sync settings:
// --------------------------------
// Sync when sublime text starts:
,"autostart": true
// Sync automatically (in seconds)
,"sync_every": 30
// Number of notes synchronized each time
,"sync_note_number": 1000
// Conflict resolution (If a file was edited on another client and also here, on sync..)
// Server Wins (Same as selecting 'Overwrite')
,"on_conflict_use_server": false
// Local is left unchanged (Same as selecting 'Cancel')
,"on_conflict_leave_alone": false
// --------------------------------
// Autosave (beta)
// --------------------------------
// Activate autosave and tell how much (in seconds) to wait
// after you stop typing to send the save
,"autosave_debounce_time": 1
// --------------------------------
// File extension support
// --------------------------------
// Which file extension should the temporal files use?
// This allows you to interact with other plugins such as
// PlainTasks defining an extension for certain note title
,"title_extension_map": [{
"title_regex": "[ST]"
,"extension": "todo"
},
{
"title_regex": "# "
,"extension": "md"
,"systemTags": ["markdown"]
}]
}
"""


class _BaseConfig:
# All subclasses of BaseConfig will be added to this mapping.
mapping: typing.Dict[str, type] = {}
Expand All @@ -39,7 +88,7 @@ def __init_subclass__(cls, **kwargs):
sys.path.insert(0, BASE_DIR)
# LOG_DIR: str = os.path.join(BASE_DIR, "logs")
# os.makedirs(LOG_DIR, exist_ok=True)
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "WARNING")

SIMPLENOTE_PROJECT_NAME: str = "Simplenote"
SIMPLENOTE_PROJECT_VERSION: str = "0.0.1"
Expand All @@ -64,12 +113,18 @@ def __init_subclass__(cls, **kwargs):

SUBLIME_USER_DIR = os.path.join(packages_path(), "User")
SIMPLENOTE_SETTINGS_FILE_PATH = SIMPLENOTE_SETTINGS_FILE
# SIMPLENOTE_SETTINGS_FILE_PATH = os.path.join(SUBLIME_USER_DIR, SIMPLENOTE_SETTINGS_FILE)
# if not os.path.exists(SIMPLENOTE_SETTINGS_FILE_PATH):
# import shutil

# default_settings = os.path.join(os.path.dirname(__file__), SIMPLENOTE_SETTINGS_FILE)
# shutil.copy(default_settings, SIMPLENOTE_SETTINGS_FILE_PATH)
SIMPLENOTE_SETTINGS_USER_FILE_PATH = os.path.join(SUBLIME_USER_DIR, SIMPLENOTE_SETTINGS_FILE)
SETTINGS_TEMPLATE: str = _SETTINGS_TEMPLATE
if not os.path.exists(SIMPLENOTE_SETTINGS_USER_FILE_PATH):
try:
with open(SIMPLENOTE_SETTINGS_USER_FILE_PATH, "r") as f:
import json

_ = json.loads(f.read())
except Exception as e:
print(e)
with open(SIMPLENOTE_SETTINGS_USER_FILE_PATH, "w+") as f:
f.write(SETTINGS_TEMPLATE)

SIMPLENOTE_CACHE_DIR = os.path.join(cache_path(), SIMPLENOTE_PROJECT_NAME)
os.makedirs(SIMPLENOTE_CACHE_DIR, exist_ok=True)
Expand Down Expand Up @@ -104,12 +159,12 @@ class Production(_BaseConfig):
CONFIG: typing.Type[_BaseConfig] = _BaseConfig.mapping.get(env, Development)

# Set environment variables
for attr in dir(CONFIG):
if attr.startswith("_"):
continue
if attr.startswith(("SIMPLENOTE", "LOG_LEVEL")):
os.environ[attr] = str(getattr(CONFIG, attr))
# print("set %s: %s" % (attr, getattr(CONFIG, attr)))
# for attr in dir(CONFIG):
# if attr.startswith("_"):
# continue
# if attr.startswith(("SIMPLENOTE", "LOG_LEVEL")):
# os.environ[attr] = str(getattr(CONFIG, attr))
# print("set %s: %s" % (attr, getattr(CONFIG, attr)))


if __name__ == "Simplenote._config":
Expand Down
9 changes: 4 additions & 5 deletions simplenotecommands.py → commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import sublime_plugin

from ._config import CONFIG
from .gui import close_view, open_view, show_message
from .models import Note
from .operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager
from .simplenote import clear_orphaned_filepaths, on_note_changed
from .lib.core import start
from .lib.gui import clear_orphaned_filepaths, close_view, on_note_changed, open_view, show_message
from .lib.models import Note
from .lib.operations import NoteCreator, NoteDeleter, NotesIndicator, NoteUpdater, OperationManager


__all__ = [
Expand All @@ -25,7 +25,6 @@
logger = logging.getLogger()


SIMPLENOTE_RELOAD_CALLS = -1
SIMPLENOTE_STARTED = False


Expand Down
140 changes: 0 additions & 140 deletions gui.py

This file was deleted.

6 changes: 3 additions & 3 deletions api.py → lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from urllib.parse import urlencode
from uuid import uuid4

from ._config import CONFIG
from .utils.patterns.singleton.base import Singleton
from .utils.request import Response, request
from .._config import CONFIG
from ..utils.patterns.singleton.base import Singleton
from ..utils.request import Response, request


logger = logging.getLogger()
Expand Down
46 changes: 46 additions & 0 deletions lib/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import logging

import sublime

from .._config import CONFIG
from .gui import edit_settings, remove_status, show_message
from .operations import OperationManager


logger = logging.getLogger()
SIMPLENOTE_STARTED = False


def sync():
manager = OperationManager()
if not manager.running:
sublime.run_command("simplenote_sync")
else:
logger.debug("Sync omitted")

settings = sublime.load_settings(CONFIG.SIMPLENOTE_SETTINGS_FILE_PATH)
sync_every = settings.get("sync_every", 0)
logger.debug(("Simplenote sync_every", sync_every))
if not isinstance(sync_every, int):
show_message("`sync_every` must be an integer. Please check settings file.")
return

if sync_every > 0:
sublime.set_timeout(sync, sync_every * 1000)


def start():
global SIMPLENOTE_STARTED
settings = sublime.load_settings("Simplenote.sublime-settings")
username = settings.get("username")
password = settings.get("password")

if username and password:
sync()
SIMPLENOTE_STARTED = True
else:
edit_settings()
show_message("Simplenote: Please configure username/password, Please check settings file.")
sublime.set_timeout(remove_status, 2000)
SIMPLENOTE_STARTED = False
return SIMPLENOTE_STARTED
Loading

0 comments on commit 542b767

Please sign in to comment.