Skip to content

Commit 43e5f93

Browse files
Uploading some changes
2 parents dcc2a6b + ac30200 commit 43e5f93

File tree

9 files changed

+153
-140
lines changed

9 files changed

+153
-140
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Kolten Fluckiger
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Binary file not shown.
-7.82 MB
Binary file not shown.
Binary file not shown.

Sources/plugin/command/command.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import asyncio
2-
import logging
3-
4-
5-
class Command:
6-
7-
def __init__(self, command, return_flag):
8-
self.command = command
9-
self.return_flag = return_flag
10-
11-
async def execute(self):
12-
try:
13-
DETACHED_PROCESS = 0x00000008
14-
process = await asyncio.create_subprocess_shell(r"{}".format(self.command), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, creationflags=DETACHED_PROCESS)
15-
stdout, stderr = await process.communicate()
16-
output = stdout.decode().strip()
17-
code = process.returncode
18-
logging.info("Output: {}".format(output))
19-
logging.info("Error Code: {}".format(code))
20-
if self.return_flag:
21-
return {"output": output, "code": code}
22-
else:
23-
return None
24-
except Exception as err:
25-
logging.critical("ERROR: {}".format(err))
26-
return None
1+
import asyncio
2+
import logging
3+
4+
5+
class Command:
6+
7+
def __init__(self, command, return_flag):
8+
self.command = command
9+
self.return_flag = return_flag
10+
11+
async def execute(self):
12+
try:
13+
DETACHED_PROCESS = 0x00000008
14+
process = await asyncio.create_subprocess_shell(r"{}".format(self.command), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, creationflags=DETACHED_PROCESS)
15+
stdout, stderr = await process.communicate()
16+
output = stdout.decode().strip()
17+
code = process.returncode
18+
logging.info("Output: {}".format(output))
19+
logging.info("Error Code: {}".format(code))
20+
if self.return_flag:
21+
return {"output": output, "code": code}
22+
else:
23+
return None
24+
except Exception as err:
25+
logging.critical("ERROR: {}".format(err))

Sources/plugin/koltenfluckiger.streamdeck-python-plugin.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1+
import sys
2+
import asyncio
13
import logging
2-
from logging.handlers import RotatingFileHandler
3-
logging.basicConfig(
4-
handlers=[RotatingFileHandler('debug.log', maxBytes=1000000, backupCount=5)],
5-
level=logging.DEBUG,
6-
format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
7-
datefmt='%Y-%m-%dT%H:%M:%S')
8-
9-
try:
10-
import sys
11-
import asyncio
12-
import re
13-
import json
14-
from websockets.client import connect
15-
import websockets
16-
17-
from process import ProcessManager
18-
from operatingsystem import OSManager
19-
from cache import CacheManager
20-
from notifier import Notifier
21-
from command import Command
22-
except Exception as err:
23-
logging.critical(err)
4+
import re
5+
import json
6+
import websockets
247

8+
from logging.handlers import RotatingFileHandler
259

10+
from process import ProcessManager
11+
from operatingsystem import OSManager
12+
from cache import CacheManager
13+
from notifier import Notifier
14+
from command import Command
2615

2716
logging.basicConfig(
28-
handlers=[RotatingFileHandler('debug.log', maxBytes=1000000, backupCount=5)],
17+
handlers=[RotatingFileHandler('debug.log', maxBytes=100000, backupCount=10)],
2918
level=logging.DEBUG,
3019
format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
3120
datefmt='%Y-%m-%dT%H:%M:%S')
@@ -60,7 +49,7 @@ async def listen(self):
6049
async def _init_websocket(self):
6150
uri = "ws://localhost:{}".format(self.port)
6251
try:
63-
self.websocket = await connect(uri)
52+
self.websocket = await websockets.client.connect(uri)
6453
return
6554
except Exception as err:
6655
logging.critical(err)
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import logging
2-
try:
3-
import platform
4-
if 'windows' in platform.system().lower():
5-
from plyer.platforms.win.notification import instance as WinInstance
6-
elif 'linux' in platform.system().lower():
7-
from plyer.platforms.linux.notification import instance as LinuxInstance
8-
elif 'mac' in platform.system().lower():
9-
from plyer.platforms.macosx.notification import instance as OSXInstance
10-
except ImportError as err:
11-
logging.critical("Import error: {}".format(err))
12-
13-
class Notifier():
14-
15-
def __init__(self, OS):
16-
if OS == OS.WINDOWS:
17-
self.instance = WinInstance()
18-
elif OS == OS.LINUX:
19-
self.instance = LinuxInstance()
20-
elif OS == OS.MACOS:
21-
self.instance = OSXInstance()
22-
23-
def notify(self, title, message):
24-
try:
25-
self.instance.notify(title=title, message=message)
26-
except Exception as err:
27-
logging.critical("Notify Error: {}".format(err))
1+
try:
2+
from operatingsystem import OSTYPE
3+
import platform
4+
import logging
5+
if 'windows' in platform.system().lower():
6+
from plyer.platforms.win.notification import instance as WinInstance
7+
elif 'linux' in platform.system().lower():
8+
from plyer.platforms.linux.notification import instance as LinuxInstance
9+
elif 'mac' in platform.system().lower():
10+
from plyer.platforms.macosx.notification import instance as OSXInstance
11+
except ImportError as err:
12+
logging.critical("Import error: {}".format(err))
13+
14+
15+
class Notifier():
16+
17+
def __init__(self, OS):
18+
if OS == OS.WINDOWS:
19+
self.instance = WinInstance()
20+
elif OS == OS.LINUX:
21+
self.instance = LinuxInstance()
22+
elif OS == OS.MACOS:
23+
self.instance = OSXInstance()
24+
25+
def notify(self, title, message):
26+
try:
27+
self.instance.notify(title=title, message=message)
28+
except Exception as err:
29+
logging.critical("Notify Error: {}".format(err))
Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,65 @@
1-
import platform
2-
import logging
3-
import sys
4-
import shutil
5-
import subprocess
6-
from pathlib import PurePosixPath, PureWindowsPath, Path
7-
from enum import Enum
8-
9-
logger = logging.getLogger()
10-
11-
class OSTYPE(Enum):
12-
13-
WINDOWS = 1
14-
UNIX = 2
15-
MACOS = 3
16-
17-
18-
class OSManager(object):
19-
20-
def __init__(self):
21-
self._setup()
22-
23-
def _setup(self):
24-
try:
25-
os_type = platform.system().lower()
26-
if 'windows' in os_type:
27-
self.OSTYPE = OSTYPE.WINDOWS
28-
self.binary_path = PureWindowsPath("pythonw.exe")
29-
else:
30-
self.OSTYPE = OSTYPE.UNIX
31-
self.binary_path = PurePosixPath('/usr/bin/env python')
32-
except Exception as err:
33-
logger.critical('ERROR AT _setup: {}'.format(err))
34-
35-
def _get_current_os(self):
36-
try:
37-
return self.OSTYPE
38-
except Exception as err:
39-
logger.critical(err)
40-
41-
def _get_current_binary_path(self):
42-
try:
43-
return self.binary_path
44-
except Exception as err:
45-
logger.critical(err)
46-
47-
def convert_path(self, path):
48-
try:
49-
return Path(r"{}".format(path)).resolve()
50-
except Exception as err:
51-
logger.critical('ERROR AT convert_path: {}'.format(err))
52-
53-
def generate_exec_path(self, path, args):
54-
try:
55-
path = self.convert_path(path)
56-
binary_path = self.convert_path(self.binary_path)
57-
full_path = r'{} {}'.format(self.binary_path, path)
58-
logger.info("Path: {}".format(path))
59-
logger.info("Full path: {}".format(full_path))
60-
return r'{} {}'.format(full_path, args)
61-
except Exception as err:
62-
logger.critical('ERROR AT generate_exec_path: {}'.format(err))
1+
import platform
2+
import logging
3+
import sys
4+
import shutil
5+
import subprocess
6+
from pathlib import PurePosixPath, PureWindowsPath, Path
7+
from enum import Enum
8+
9+
logger = logging.getLogger()
10+
11+
class OSTYPE(Enum):
12+
13+
WINDOWS = 1
14+
UNIX = 2
15+
MACOS = 3
16+
17+
18+
class OSManager(object):
19+
20+
def __init__(self):
21+
self._setup()
22+
23+
def _setup(self):
24+
try:
25+
os_type = platform.system().lower()
26+
if 'windows' in os_type:
27+
self.OSTYPE = OSTYPE.WINDOWS
28+
self.binary_path = PureWindowsPath("pythonw.exe")
29+
else:
30+
self.OSTYPE = OSTYPE.UNIX
31+
self.binary_path = PurePosixPath('/usr/bin/env python')
32+
except Exception as err:
33+
logger.critical('ERROR AT _setup: {}'.format(err))
34+
35+
def _get_current_os(self):
36+
try:
37+
return self.OSTYPE
38+
except Exception as err:
39+
logger.critical(err)
40+
41+
def _get_current_binary_path(self):
42+
try:
43+
return self.binary_path
44+
except Exception as err:
45+
logger.critical(err)
46+
47+
def convert_path(self, path):
48+
try:
49+
if self.OSTYPE == OSTYPE.WINDOWS:
50+
return PureWindowsPath(Path(r"{}".format(path)).resolve())
51+
else:
52+
return PurePosixPath(path)
53+
except Exception as err:
54+
logger.critical('ERROR AT convert_path: {}'.format(err))
55+
56+
def generate_exec_path(self, path, args):
57+
try:
58+
path = self.convert_path(path)
59+
binary_path = self.convert_path(self.binary_path)
60+
full_path = r'{} {}'.format(self.binary_path, path)
61+
logger.info("Path: {}".format(path))
62+
logger.info("Full path: {}".format(full_path))
63+
return r'{} {}'.format(full_path, args)
64+
except Exception as err:
65+
logger.critical('ERROR AT generate_exec_path: {}'.format(err))

Sources/plugin/process/process.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ async def process(self):
2020
command = await self.queue.get()
2121
result = await command.execute()
2222
self.queue.task_done()
23-
logging.critical(r"OUTPUT: {}".format(result))
2423
if result:
2524
output = result['output']
2625
code = result['code']

0 commit comments

Comments
 (0)