-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from sisoe24/0.1.0a
- Loading branch information
Showing
30 changed files
with
1,117 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
other | ||
dist | ||
tmp | ||
*tmp | ||
|
||
|
||
.DS_Store | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.3 | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
# coding: utf-8 | ||
from __future__ import print_function | ||
|
||
import re | ||
from textwrap import dedent | ||
|
||
from PySide2.QtGui import QClipboard | ||
|
||
NUKE_VERSION_STRING = '13.0v1' | ||
|
||
env = { | ||
'NukeVersionMajor': 13 | ||
} | ||
|
||
|
||
def nodeCopy(s): | ||
"""internal implementation of nuke.nodeCopy for testing purpose.""" | ||
copy_tmp = dedent(""" | ||
set cut_paste_input [stack 0] | ||
version 13.0 v1 | ||
push $cut_paste_input | ||
Blur { | ||
size {{curve x-16 100 x25 1.8 x101 100}} | ||
name Blur1 | ||
selected true | ||
xpos -150 | ||
ypos -277 | ||
} | ||
Blur { | ||
inputs 0 | ||
name Blur2 | ||
selected true | ||
xpos -40 | ||
ypos -301 | ||
} | ||
""").strip() | ||
if re.match(r'^%.+%$', s): | ||
clipboard = QClipboard() | ||
clipboard.setText(copy_tmp) | ||
else: | ||
with open(s, 'w') as file: | ||
file.write(copy_tmp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .server import Server | ||
from .socket import Socket | ||
from .test_client import ClientTest | ||
from .nss_server import Server | ||
from .nss_socket import Socket | ||
from .nss_client import TestClient, SendNodesClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# coding: utf-8 | ||
from __future__ import print_function, with_statement | ||
|
||
import json | ||
import random | ||
import logging | ||
|
||
from abc import abstractmethod, ABCMeta | ||
|
||
from PySide2.QtNetwork import QHostAddress, QTcpSocket | ||
|
||
from .. import nuke | ||
from ..utils import AppSettings, validate_output | ||
|
||
|
||
LOGGER = logging.getLogger('NukeServerSocket.client') | ||
|
||
|
||
class NetworkAddresses(object): | ||
"""Convenient class with network addresses""" | ||
|
||
def __init__(self): | ||
self.settings = AppSettings() | ||
|
||
@property | ||
def port(self): # type: () -> int | ||
"""Get port data from the configuration.ini file""" | ||
return int(self.settings.value('server/port', 54321)) | ||
|
||
@property | ||
def hostname(self): # type: () -> str | ||
"""Get host address data from the configuration.ini file""" | ||
return self.settings.value('server/send_to_address', '127.0.0.1') | ||
|
||
@property | ||
def local_host(self): # type: () -> QHostAddress | ||
"""Get local host address QHostAddress object""" | ||
# REVIEW: why not returning '127.0.0.1'? | ||
return QHostAddress.LocalHost | ||
|
||
|
||
class QBaseClient(object): | ||
__metaclass__ = ABCMeta | ||
|
||
def __init__(self, hostname, port): # type: (str, int) -> None | ||
|
||
self.tcp_host = hostname | ||
LOGGER.debug('client host: %s', self.tcp_host) | ||
|
||
self.tcp_port = port | ||
LOGGER.debug('client port: %s', self.tcp_port) | ||
|
||
self.socket = QTcpSocket() | ||
LOGGER.debug('creating socket: %s', self.socket) | ||
|
||
self.socket.readyRead.connect(self.read_data) | ||
self.socket.connected.connect(self.on_connected) | ||
self.socket.disconnected.connect(self.on_disconnect) | ||
self.socket.error.connect(self.on_error) | ||
|
||
@abstractmethod | ||
def on_connected(self): | ||
# TODO: docstring not accurate anymore | ||
"""Method needs to return a string with the text to send write""" | ||
|
||
def write_data(self, data): | ||
self.socket.write(validate_output(json.dumps(data))) | ||
LOGGER.debug('message sent: %s', data) | ||
|
||
self.socket.flush() | ||
self.socket.disconnectFromHost() | ||
|
||
def on_disconnect(self): | ||
LOGGER.debug('Disconnected from host') | ||
|
||
def connect(self): | ||
LOGGER.debug('Connecting to host: %s %s', self.tcp_host, self.tcp_port) | ||
self.socket.connectToHost(self.tcp_host, self.tcp_port) | ||
|
||
def on_error(self, error): | ||
LOGGER.error("QBaseClient Error: %s", error) | ||
|
||
def read_data(self): | ||
LOGGER.debug('Reading data: %s', self.socket.readAll()) | ||
|
||
|
||
class TestClient(QBaseClient): | ||
"""Test Socket by send a sample text to the local host port.""" | ||
|
||
def __init__(self, addresses=NetworkAddresses()): # type: (NetworkAddresses) -> None | ||
QBaseClient.__init__(self, addresses.local_host, addresses.port) | ||
|
||
def on_connected(self): | ||
LOGGER.debug('TestClient -> Connected to host') | ||
r = random.randint(1, 50) | ||
|
||
output_text = { | ||
"text": "from __future__ import print_function; print('Hello from Test Client', %s)" % r, | ||
"file": "path/to/tmp_file.py" | ||
} | ||
|
||
self.write_data(output_text) | ||
|
||
|
||
class SendNodesClient(QBaseClient): | ||
"""Send nuke nodes using the Qt client socket.""" | ||
|
||
def __init__(self, addresses=NetworkAddresses()): # type: (NetworkAddresses, dict) -> None | ||
QBaseClient.__init__(self, addresses.hostname, addresses.port) | ||
self.transfer_data = self.transfer_file_content() | ||
|
||
def on_connected(self): | ||
"""When connected, send the content of the transfer file as data to the socket.""" | ||
LOGGER.debug('SendNodesClient -> Connected to host') | ||
self.write_data(self.transfer_data) | ||
|
||
def transfer_file_content(self): | ||
settings = AppSettings() | ||
transfer_file = settings.value('path/transfer_file') | ||
|
||
# this will also create the file if it doesn't exists already | ||
nuke.nodeCopy(transfer_file) | ||
|
||
with open(transfer_file) as file: | ||
return {"text": file.read(), "file": transfer_file} |
Oops, something went wrong.