<commit_before>"""
Theme Scheduler

Copyright (c) 2012 <NAME> <<EMAIL>>
License: MIT

Example Theme file (ThemeScheduler.sublime-settings):
{
    "enabled": true,
    "use_sub_notify": false,
    "themes":
    [
        {
            "theme": "Packages/User/Color Scheme/sometheme.tmTheme",
            "time": "21:30"
        },
        {
            "theme": "Packages/User/Color Scheme/someothertheme.tmTheme",
            "time": "8:30"
        }
    ]
}

Uses multiconf for "enabled" and "themes" key for platform or host specific settings.
See multiconf.py for more details.

Creates theme file if it doesn't exists (turned off by default).
"""

from datetime import datetime, timedelta
import time
import sublime
import sublime_plugin
from collections import namedtuple
import _thread as thread
from .lib.file_strip.json import sanitize_json
from .lib.multiconf import get as multiget
import json
from os.path import exists, join, abspath, dirname
LOAD_RETRIES = 5


def log(s):
    print("ThemeScheduler: %s" % s)


def debug_log(s):
    if SETTINGS.get("debug", False):
        log(s)


def create_settings(settings_path):
    err = False
    default_theme = {
        "enabled": False,
        "themes": [],
    }
    j = json.dumps(default_theme, sort_keys=True, indent=4, separators=(',', ': '))
    try:
        with open(settings_path, 'w') as f:
            f.write(j + "\n")
    except:
        err = True
    return err


def total_seconds(t):
    return (t.microseconds + (t.seconds + t.days * 24 * 3600) * 10 ** 6) / 10 ** 6


def get_current_time():
    now = datetime.now()
    seconds = total_seconds(timedelta(hours=now.hour, minutes=now.minute, seconds=now.second))
    return seconds, now


def translate_time(t):
    tm = time.strptime(t, '%H:%M')
    return total_seconds(timedelta(hours=tm.tm_hour, minutes=tm.tm_min, seconds=tm.tm_sec))


def display_message(msg):
    settings = sublime.load_settings("ThemeScheduler.sublime-settings")
    use_sub_notify = multiget(settings, "use_sub_notify", False)
    ThemeScheduler.dialog_open = True
    if use_sub_notify:
        sublime.run_command("sub_notify_info", {"title": "ThemeScheduler", "msg": msg})
    else:
        if ThemeScheduler.dialog_open:
            print("Dialog already open!")
            print(msg)
            return
        sublime.ok_cancel_dialog(msg)
    ThemeScheduler.update = True
    ThemeScheduler.dialog_open = False


class ThemeSchedulerGetNextChangeCommand(sublime_plugin.ApplicationCommand):
    def run(self):
        sublime.message_dialog("ThemeScheduler: Next Change @\n" + str(ThemeScheduler.next_change))

<commit_msg>- Use correct command for SubNotify<commit_after>"""
Theme Scheduler

Copyright (c) 2012 <NAME> <<EMAIL>>
License: MIT

Example Theme file (ThemeScheduler.sublime-settings):
{
    "enabled": true,
    "use_sub_notify": false,
    "themes":
    [
        {
            "theme": "Packages/User/Color Scheme/sometheme.tmTheme",
            "time": "21:30"
        },
        {
            "theme": "Packages/User/Color Scheme/someothertheme.tmTheme",
            "time": "8:30"
        }
    ]
}

Uses multiconf for "enabled" and "themes" key for platform or host specific settings.
See multiconf.py for more details.

Creates theme file if it doesn't exists (turned off by default).
"""

from datetime import datetime, timedelta
import time
import sublime
import sublime_plugin
from collections import namedtuple
import _thread as thread
from .lib.file_strip.json import sanitize_json
from .lib.multiconf import get as multiget
import json
from os.path import exists, join, abspath, dirname
LOAD_RETRIES = 5


def log(s):
    print("ThemeScheduler: %s" % s)


def debug_log(s):
    if SETTINGS.get("debug", False):
        log(s)


def create_settings(settings_path):
    err = False
    default_theme = {
        "enabled": False,
        "themes": [],
    }
    j = json.dumps(default_theme, sort_keys=True, indent=4, separators=(',', ': '))
    try:
        with open(settings_path, 'w') as f:
            f.write(j + "\n")
    except:
        err = True
    return err


def total_seconds(t):
    return (t.microseconds + (t.seconds + t.days * 24 * 3600) * 10 ** 6) / 10 ** 6


def get_current_time():
    now = datetime.now()
    seconds = total_seconds(timedelta(hours=now.hour, minutes=now.minute, seconds=now.second))
    return seconds, now


def translate_time(t):
    tm = time.strptime(t, '%H:%M')
    return total_seconds(timedelta(hours=tm.tm_hour, minutes=tm.tm_min, seconds=tm.tm_sec))


def display_message(msg):
    settings = sublime.load_settings("ThemeScheduler.sublime-settings")
    use_sub_notify = multiget(settings, "use_sub_notify", False)
    ThemeScheduler.dialog_open = True
    if use_sub_notify:
        sublime.run_command("sub_notify", {"title": "ThemeScheduler", "msg": msg})
    else:
        if ThemeScheduler.dialog_open:
            print("Dialog already open!")
            print(msg)
            return
        sublime.ok_cancel_dialog(msg)
    ThemeScheduler.update = True
    ThemeScheduler.dialog_open = False


class ThemeSchedulerGetNextChangeCommand(sublime_plugin.ApplicationCommand):
    def run(self):
        sublime.message_dialog("ThemeScheduler: Next Change @\n" + str(ThemeScheduler.next_change))


{'fraction_non_alphanumeric': 0.11788079470198676, 'fraction_numerical': 0.00946073793755913, 'mean_word_length': 3.1919111816019035, 'pattern_counts': {'":': 22, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3050753', 'n_tokens_mistral': 1777, 'n_tokens_neox': 1690, 'n_words': 417}