Skip to content

Commit

Permalink
Merge pull request #681 from LexiconCode/settings_dependency_removal
Browse files Browse the repository at this point in the history
Remove settings as a hard dependency for Dependency.py
  • Loading branch information
LexiconCode authored Aug 20, 2019
2 parents f3781bb + 5fbd12f commit 783b8eb
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 39 deletions.
12 changes: 8 additions & 4 deletions _caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
import time, socket, os
from dragonfly import (get_engine, Function, Grammar, Playback, Dictation, Choice, Pause,
RunCommand)
from castervoice.lib.ccr.standard import SymbolSpecs

from castervoice.lib.ctrl.dependencies import DependencyMan # requires nothing

DependencyMan().initialize()

_NEXUS = None
from castervoice.lib import settings # requires nothing
from castervoice.lib import settings # requires toml
if settings.SYSTEM_INFORMATION["platform"] != "win32":
raise SystemError("Your platform is not currently supported by Caster.")
settings.WSR = __name__ == "__main__"
from castervoice.lib import utilities # requires settings
from castervoice.lib.ccr.standard import SymbolSpecs
if settings.WSR:
SymbolSpecs.set_cancel_word("escape")
from castervoice.lib import control
_NEXUS = control.nexus()
_NEXUS.dep.initialize()
from castervoice.lib.ctrl.dependencies import find_pip, update
from castervoice.lib import navigation
navigation.initialize_clipboard(_NEXUS)
Expand Down Expand Up @@ -68,8 +71,10 @@ def change_monitor():
else:
print("This command requires SikuliX to be enabled in the settings file")


pip = find_pip()


class MainRule(MergeRule):
@staticmethod
def generate_ccr_choices(nexus):
Expand All @@ -85,7 +90,6 @@ def generate_sm_ccr_choices(nexus):
choices[ccr_choice] = ccr_choice
return Choice("name2", choices)


mapping = {
# update management
"update caster":
Expand Down
47 changes: 33 additions & 14 deletions castervoice/lib/ctrl/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
@author: synkarius
'''

import os, sys, socket, time, pkg_resources, subprocess
try:
import mock
except ImportError:
from unittest import mock

import os, sys, socket, time, pkg_resources, subprocess, inspect
import setuptools
from pkg_resources import VersionConflict, DistributionNotFound
from subprocess import Popen
from castervoice.lib import settings

update = None

Expand Down Expand Up @@ -49,11 +54,11 @@ def internet_check(host="1.1.1.1", port=53, timeout=3):
return True
except socket.error as e:
if e.errno == 11001:
print ("Caster: Internet check failed to resolve CloudFire DNS")
if e.errno == 10051: # Unreachable Network
print("Caster: Internet check failed to resolve CloudFire DNS")
if e.errno == 10051: # Unreachable Network
pass
if e.errno not in (10051, 11001): # Unknown Error
print (e.errno)
if e.errno not in (10051, 11001): # Unknown Error
print(e.errno)
return False


Expand Down Expand Up @@ -86,11 +91,13 @@ def dependency_check(command=None):


def dep_missing():
# For classic: Checks for missing dependencies parsing requirements.txt
base = os.path.normpath(settings.SETTINGS["paths"]["BASE_PATH"] + os.sep + os.pardir)
requirements = os.path.join(base, "requirements.txt")
with open(requirements) as f:
requirements = f.read().splitlines()
with mock.patch.object(setuptools, 'setup') as mock_setup:
import setup # This is setup.py which calls setuptools.setup

# called arguments are in `mock_setup.call_args`
args, kwargs = mock_setup.call_args
requirements = kwargs.get('install_requires', [])

for dep in requirements:
try:
pkg_resources.require("{}".format(dep))
Expand Down Expand Up @@ -133,18 +140,30 @@ def dep_min_version():
.format(pippackages))


def online_mode():
# Tries to import settings on failure online_mode is true
try:
from castervoice.lib import settings
if settings.SETTINGS["miscellaneous"]["online_mode"] is True:
return True
else:
return False
except ImportError:
return True


class DependencyMan:
# Initializes functions
def initialize(self):
install = install_type()
if install is "classic":
dep_min_version()
dep_missing()
if settings.SETTINGS["miscellaneous"]["online_mode"]:
if internet_check():
if online_mode() == True:
if internet_check() == True:
dependency_check(command="dragonfly2")
if install is "pip":
dependency_check(command="castervoice")
dependency_check(command="dragonfly2")
else:
print("\nCaster: Network off-line check network connection\n")
else:
Expand Down
3 changes: 0 additions & 3 deletions castervoice/lib/ctrl/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from dragonfly.grammar.recobs import RecognitionHistory

from castervoice.lib import settings
from castervoice.lib.ctrl.dependencies import DependencyMan
from castervoice.lib.dfplus.communication import Communicator
from castervoice.lib.dfplus.merge.ccrmerger import CCRMerger
from castervoice.lib.dfplus.state.stack import CasterState
Expand All @@ -26,8 +25,6 @@ def __init__(self, real_merger_config=True):

self.comm = Communicator()

self.dep = DependencyMan()

self.macros_grammar = Grammar("recorded_macros")

self.merger = CCRMerger(real_merger_config)
Expand Down
53 changes: 36 additions & 17 deletions castervoice/lib/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from ctypes import windll
from subprocess import Popen


import dragonfly
from dragonfly import Choice, monitors, Pause
from castervoice.asynch.mouse.legion import LegionScanner
from castervoice.lib import control, settings, utilities, textformat
from castervoice.lib.actions import Key, Text, Mouse
from castervoice.lib.clipboard import Clipboard
from castervoice.lib.ctrl.dependencies import DependencyMan

DIRECTION_STANDARD = {
"sauce [E]": "up",
Expand Down Expand Up @@ -42,6 +42,7 @@
"token": "TOKEN"
})


def get_direction_choice(name):
global DIRECTION_STANDARD
return Choice(name, DIRECTION_STANDARD)
Expand All @@ -54,7 +55,7 @@ def initialize_clipboard(nexus):


def mouse_alternates(mode, nexus, monitor=1):
if nexus.dep.PIL:
if DependencyMan.PIL:
if mode == "legion" and not utilities.window_exists(None, "legiongrid"):
r = monitors[int(monitor) - 1].rectangle
bbox = [
Expand Down Expand Up @@ -86,6 +87,7 @@ def mouse_alternates(mode, nexus, monitor=1):
else:
utilities.availability_message(mode.title(), "PIL")


def _text_to_clipboard(keystroke, nnavi500, nexus):
if nnavi500 == 1:
Key(keystroke).execute()
Expand All @@ -109,12 +111,15 @@ def _text_to_clipboard(keystroke, nnavi500, nexus):
break
cb.copy_to_system()


def stoosh_keep_clipboard(nnavi500, nexus):
_text_to_clipboard("c-c", nnavi500, nexus)


def cut_keep_clipboard(nnavi500, nexus):
_text_to_clipboard("c-x", nnavi500, nexus)


def drop_keep_clipboard(nnavi500, nexus, capitalization, spacing):
# Maintain standard spark functionality for non-strings
if capitalization == 0 and spacing == 0 and nnavi500 == 1:
Expand Down Expand Up @@ -177,13 +182,13 @@ def mouse_click(nexus, button):
Mouse(button).execute()


left_click = lambda nexus: mouse_click(nexus, "left")
right_click = lambda nexus: mouse_click(nexus, "right")
left_click = lambda nexus: mouse_click(nexus, "left")
right_click = lambda nexus: mouse_click(nexus, "right")
middle_click = lambda nexus: mouse_click(nexus, "middle")
left_down = lambda nexus: mouse_click(nexus, "left:down")
left_up = lambda nexus: mouse_click(nexus, "left:up")
right_down = lambda nexus: mouse_click(nexus, "right:down")
right_up = lambda nexus: mouse_click(nexus, "right:up")
left_down = lambda nexus: mouse_click(nexus, "left:down")
left_up = lambda nexus: mouse_click(nexus, "left:up")
right_down = lambda nexus: mouse_click(nexus, "right:down")
right_up = lambda nexus: mouse_click(nexus, "right:up")


def wheel_scroll(direction, nnavi500):
Expand Down Expand Up @@ -225,6 +230,7 @@ def next_line(semi):
Text(semi).execute()
Key("enter").execute()


'''
function for performing an action on one or more lines in a text editor.
E.g.: "cut 128 by 148"
Expand All @@ -236,14 +242,27 @@ def next_line(semi):
wait: some applications are slow and need a pause between keystrokes, e.g. wait="/10"
upon_arrival: keystroke to be pressed after arriving at the first line. Should have a comma afterwards, e.g. "home, "
'''
def action_lines(action, ln1, ln2, go_to_line="c-g", select_line_down="s-down", wait="", upon_arrival=""):
num_lines = max(int(ln2)-int(ln1)+1, int(ln1)-int(ln2)+1) if ln2 else 1
top_line = min(int(ln2), int(ln1)) if ln2 else int(ln1)
command = Key(go_to_line) + Text(str(top_line)) + Key("enter%s, %s%s%s:%s, %s" % (wait, upon_arrival, select_line_down, wait, str(num_lines), action))


def action_lines(action,
ln1,
ln2,
go_to_line="c-g",
select_line_down="s-down",
wait="",
upon_arrival=""):
num_lines = max(int(ln2) - int(ln1) + 1, int(ln1) - int(ln2) + 1) if ln2 else 1
top_line = min(int(ln2), int(ln1)) if ln2 else int(ln1)
command = Key(go_to_line) + Text(str(top_line)) + Key(
"enter%s, %s%s%s:%s, %s" %
(wait, upon_arrival, select_line_down, wait, str(num_lines), action))
command.execute()

actions = {"select" : "",
"copy" : "c-c",
"cut" : "c-x",
"paste" : "c-v",
"delete" : "backspace"}

actions = {
"select": "",
"copy": "c-c",
"cut": "c-x",
"paste": "c-v",
"delete": "backspace"
}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class dev_install(develop):
def run(self):
develop.run(self)

with open("docs/README.md", "r") as fh:
readmepath = os.path.normpath(os.path.join(here, "docs/README.md"))
with open(readmepath, "r") as fh:
long_description = fh.read()

setuptools.setup(
Expand Down

0 comments on commit 783b8eb

Please sign in to comment.