-
Notifications
You must be signed in to change notification settings - Fork 2
/
pypelyne_client.py
1903 lines (1491 loc) · 78.4 KB
/
pypelyne_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sip
import sys
import subprocess
import platform
import re
import shutil
import random
import datetime
import getpass
import threading
import socket
import json
# TODO: check module colorlog and coloredlogs
# http://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output
import logging
from operator import *
# the mouse events need to go to qgraphicsview, which now comes directly from the ui file.
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.uic import *
from PyQt4.QtOpenGL import *
from random import *
from src.pypelyneConfigurationWindow import *
from src.bezierLine import *
from src.graphicsScene import *
from src.screenCast import *
from src.timeTracker import *
from src.listScreenCasts import *
from src.nodeWidget import *
from src.playerWidget import *
import settings as SETTINGS
import xml.etree.ElementTree as ET
try:
from src.vlc import *
except WindowsError, e:
print 'failed to import vlc:', e
# raise ImportError('failed to import vlc')
app = None
# TODO: jumping from shots to asset loader does not update tab widget title correctly
class PypelyneMainWindow(QMainWindow):
addNewScreenCast = pyqtSignal()
def __init__(self, parent=None):
super(PypelyneMainWindow, self).__init__(parent)
# self.serverHost = SERVER_IP
# self.serverPort = int(SETTINGS.SERVER_PORT)
# self.portRange = int(SETTINGS.SERVER_PORT_RANGE)
# self.serverPort = 50002
self.server_alive = False
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.content_tabs = SETTINGS.CONTENT_TABS
# self.connectServer()
if SETTINGS.USE_SERVER:
logging.info('connecting to server')
logging.info('server ip is %s' % SETTINGS.SERVER_IP)
while True:
try:
logging.info('trying to connect to %s:%s' % (SETTINGS.SERVER_IP, SETTINGS.SERVER_PORT))
self.socket.connect((SETTINGS.SERVER_IP, SETTINGS.SERVER_PORT))
logging.info('connection to server successful')
self.server_alive = True
break
except:
logging.info('connection failed')
else:
self.server_alive = False
self.pypelyne_root = os.getcwd()
self.current_platform = platform.system()
self.operating_system = self.current_platform.lower()
self.architectures = ['x32', 'x64']
self.tool_items = []
if sys.maxsize <= 2**32:
self.architecture = self.architectures[0]
elif sys.maxsize > 2**32:
self.architecture = self.architectures[1]
self.user = getpass.getuser()
print self.operating_system, self.architecture, self.user
self.current_content_item = None
self.set_projects_root()
if self.current_platform == "Windows":
# print 'platform not fully supported'
logging.info('Windows not fully supported')
self.file_explorer = SETTINGS.FILE_EXPLORER_WIN
self.tar_exec = SETTINGS.TAR_EXEC_WIN
# self.projects_root = projectsRootWin
self.libraryRoot = SETTINGS.LIBRARY_ROOT_WIN
self.audioFolder = SETTINGS.AUDIO_FOLDER_WIN
if SETTINGS.SCREEN_CAST_EXEC_WIN[1:].startswith(':' + os.sep):
self.screenCastExec = SETTINGS.SCREEN_CAST_EXEC_WIN
else:
self.screenCastExec = os.path.join(self.pypelyne_root, SETTINGS.SCREEN_CAST_EXEC_WIN)
if len(SETTINGS.SEQUENCE_EXEC_RV_WIN) <= 0 or not os.path.exists(SETTINGS.SEQUENCE_EXEC_RV_WIN):
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_WIN
self.rv = False
else:
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_RV_WIN
self.rv = True
elif self.current_platform == "Darwin":
logging.info('welcome to pypelyne for darwin')
self.file_explorer = SETTINGS.FILE_EXPLORER_DARWIN
self.tar_exec = SETTINGS.TAR_EXEC_DARWIN
# self.projects_root = projectsRootDarwin
self.libraryRoot = SETTINGS.LIBRARY_ROOT_DARWIN
self.audioFolder = SETTINGS.AUDIO_FOLDER_DARWIN
if SETTINGS.SCREEN_CAST_EXEC_DARWIN.startswith(os.sep):
self.screenCastExec = SETTINGS.SCREEN_CAST_EXEC_DARWIN
else:
self.screenCastExec = os.path.join(self.pypelyne_root, SETTINGS.SCREEN_CAST_EXEC_DARWIN)
if len(SETTINGS.SEQUENCE_EXEC_RV_DARWIN) <= 0 or not os.path.exists(SETTINGS.SEQUENCE_EXEC_RV_DARWIN):
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_DARWIN
self.rv = False
else:
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_RV_DARWIN
self.rv = True
elif self.current_platform == "Linux":
logging.info('linux not fully supported')
if os.path.exists(SETTINGS.FILE_EXPLORER_LINUX_GNOME):
self.file_explorer = SETTINGS.FILE_EXPLORER_LINUX_GNOME
elif os.path.exists(SETTINGS.FILE_EXPLORER_LINUX_KDE):
self.file_explorer = SETTINGS.FILE_EXPLORER_LINUX_KDE
else:
logging.warning('no valid file explorer found for linux')
# quit()
self.tar_exec = SETTINGS.TAR_EXEC_LINUX
# self.projects_root = projectsRootLinux
self.libraryRoot = SETTINGS.LIBRARY_ROOT_LINUX
# self.audioFolder = SETTINGS.AUDIO_FOLDER_LINUX
if SETTINGS.SCREEN_CAST_EXEC_LINUX.startswith(os.sep):
self.screenCastExec = SETTINGS.SCREEN_CAST_EXEC_LINUX
else:
self.screenCastExec = os.path.join(self.pypelyne_root, SETTINGS.SCREEN_CAST_EXEC_LINUX)
if len(SETTINGS.SEQUENCE_EXEC_RV_LINUX) <= 0 or not os.path.exists(SETTINGS.SEQUENCE_EXEC_RV_LINUX):
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_LINUX
self.rv = False
else:
self.sequence_exec = SETTINGS.SEQUENCE_EXEC_RV_LINUX
self.rv = True
else:
print 'platform unknown. not supported. bye.'
quit()
# print self.libraryRoot
if not os.path.exists(self.libraryRoot) and not self.libraryRoot == None and not self.libraryRoot == '':
os.makedirs(self.libraryRoot, mode=0777)
logging.info('library root directory created')
self.node_widgets = []
self.qprocesses = []
self.open_nodes = []
self.timeTrackers = []
self.screenCasts = []
self.screen_casts_window_open = None
self.ui = loadUi(os.path.join(self.pypelyne_root, 'ui', 'pypelyneMainWindow.ui'), self)
self.valueApplicationsXML = os.path.join(self.pypelyne_root, 'conf', 'valueApplications.xml')
self.nodeView.setVisible(False)
self.assetsShotsTabWidget.setVisible(False)
self.statusBox.setVisible(False)
self.nodeOptionsWindow.setVisible(False)
self.descriptionWindow.setVisible(False)
self.openPushButton.setVisible(True)
self.checkBoxDescription.setVisible(False)
self.configPushButton.setVisible(False)
if not SETTINGS.USE_SCREEN_CAST:
self.screenCastsPushButton.setVisible(False)
self.openPushButton.setEnabled(False)
self.compute_value_outputs()
# Scene view
self.scene = SceneView(self)
self.nodeView.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))
self.nodeView.setScene(self.scene)
self.nodeView.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.nodeView.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
# self.nodeView.setSceneRect(0, 0, 630, 555)
self.scalingFactor = 1
self.currentContent = None
self.mapSize = (512, 512)
# self.scene = GraphicsScene(self)
# self.scene.addRect(QRectF(0, 0, self.mapSize), Qt.red)
# self.addRect()
# self.boundary = self.scene.addRect(QRectF(-1000, -1000, 1000, 1000), Qt.red)
# self.view = QGraphicsView()
# self.scene.setScene(self.scene)
# self.scene.resize(self.scene.width(), self.scene.height())
# self.setCentralWidget(self.view)
# Graphics View
self.nodeView.wheelEvent = self.graphicsView_wheelEvent
# self.nodeView.resizeEvent = self.graphicsView_resizeEvent
self.nodeView.setBackgroundBrush(QBrush(QColor(60, 60, 60, 255), Qt.SolidPattern))
self.tools = None
self.tasks = None
# Projects
self.addP_projects()
# Tools
# self.tools_dict = {}
self.add_tools()
self.audio_folder_content = []
if os.path.exists(SETTINGS.AUDIO_FOLDER_DARWIN):
logging.info('audioFolder found at %s' % SETTINGS.AUDIO_FOLDER_DARWIN)
self.add_player()
self.runToolPushButton.clicked.connect(self.run_tool)
self.checkBoxConsole.stateChanged.connect(self.toggleConsole)
self.checkBoxNodeName.stateChanged.connect(self.toggle_node_name)
self.checkBoxDescription.stateChanged.connect(self.toggleDescription)
self.checkBoxContentBrowser.stateChanged.connect(self.toggleContentBrowser)
# self.checkBoxNodesWindow.stateChanged.connect(self.toggleNodesWindow)
# self.scene.nodeClicked.connect(self.setWidgetMenu)
# configuration window
self.configPushButton.clicked.connect(self.configurationWindow)
self.screenCastsPushButton.clicked.connect(self.screen_casts_window)
self.scene.nodeSelect.connect(self.set_node_widget)
self.scene.nodeDeselect.connect(self.clear_node_widget)
self.openPushButton.clicked.connect(lambda: self.locate_content(os.path.join(self.projects_root, str(self.projectComboBox.currentText()))))
self.clipBoard = QApplication.clipboard()
# self.scene = SceneView()
self.scene.textMessage.connect(self.sendTextToBox)
# self.scene.nodeClicked.connect(self.setNodeMenuWidget)
# self.scene.nodeMenu.connect(self.setWidgetMenu)
# self.scene.nodeMenuArea.connect(self.updateNodeMenu)
# print self._tools
# print self._tool_items
# def connectServer(self):
# @property
# def _user(self):
# return self.user
# @property
# def _exclusions(self):
# return SETTINGS.EXCLUSIONS
# @property
# def _image_extensions(self):
# return SETTINGS.IMAGE_EXTENSIONS
# @property
# def _movie_extensions(self):
# return SETTINGS.MOVIE_EXTENSIONS
# @property
# def _sequence_exec(self):
# return self.sequenceExec
# @property
# def _current_platform(self):
# return self.current_platform
# @property
# def _pypelyne_root(self):
# return self.pypelyne_root
# @property
# def _projects_root(self):
# return self.projects_root
@property
def _current_content(self):
current_content_index = self.assetsShotsTabWidget.currentIndex()
# returns dict like {'content': 'assets', 'abbreviation': 'AST', 'loader_color': '#FFFF00', 'saver_color': '#FFFF33'}
return self.content_tabs[current_content_index]
@property
def _tasks(self):
if self.tasks is None:
print 'def _tasks(self):'
logging.info('parsing tasks')
tasks_conf_file = os.path.join(os.path.abspath(r'conf'), r'tasks.json')
# print tasks_conf_file
json_file = open(tasks_conf_file)
tasks_conf = json.load(json_file)
json_file.close()
self.tasks = [task for task in tasks_conf if task['task_enable']]
# print tasks_conf
# print self.tasks
return self.tasks
# return 'hello'
@property
def _tools(self):
if self.tools is None:
print 'def _tools(self):'
logging.info('parsing tools')
app_conf_root = os.path.join(os.path.abspath(r'conf'), r'tools', r'applications')
app_conf_files = [os.path.join(app_conf_root, f) for f in os.listdir(app_conf_root) if not f.startswith('_') and f not in SETTINGS.EXCLUSIONS and f.split('.')[-1].endswith('json')]
self.tools = []
# test_items = ['maya.json', 'photoshop.json']
# app_conf_files = []
# for test_item in test_items:
# app_conf_files.append(os.path.join(app_conf_root, test_item))
for app_conf_file in app_conf_files:
source_file = os.path.join(app_conf_root, app_conf_file)
tool = {}
json_file = open(app_conf_file)
app_conf = json.load(json_file)
json_file.close()
logging.info('processing source file: %s' % source_file)
# print app_conf
if app_conf['family_enable']:
logging.info('checking system for family: %s' % app_conf['family'])
# all the family related stuff
# source_file = source_file
family = app_conf[u'family']
vendor = app_conf[u'vendor']
abbreviation = app_conf[u'abbreviation']
for release in app_conf[u'releases']:
# print release
# type(release) = dict
logging.info('checking system for release: %s' % release[u'release_number'])
# and all the version/release related stuff
release_number = release[u'release_number']
release_extension = release[u'release_extension']
project_template = release[u'project_template']
project_workspace_template = release[u'project_workspace_template']
project_directories = release[u'project_directories']
# needs_workspace = release[u'needs_workspace']
default_outputs = release[u'default_outputs']
architecture_fallback = release[u'architecture_fallback']
if self.architecture == 'x64' and architecture_fallback:
architecture_fallback = True
elif self.architecture == 'x32':
architecture_fallback = False
label_x32 = vendor + ' ' + family + ' ' + release_number + ' (%s)' % self.architectures[0]
label_x64 = vendor + ' ' + family + ' ' + release_number + ' (%s)' % self.architectures[1]
project_directories_list = []
# default_outputs_list = []
for project_directory in project_directories:
project_directory = project_directory.replace('%', os.sep)
project_directories_list.append(project_directory)
# for default_output in default_outputs:
# default_outputs_list.append(default_output)
for platform in release['platforms']:
if platform.has_key(self.operating_system):
# general information:
executable_x32 = platform[self.operating_system][u'executable_x32']
executable_x64 = platform[self.operating_system][u'executable_x64']
flags_x32 = platform[self.operating_system][u'flags_x32']
flags_x64 = platform[self.operating_system][u'flags_x64']
project_workspace_flag = platform[self.operating_system][u'project_workspace_flag']
project_workspace_parent_directory_level = platform[self.operating_system][u'project_workspace_parent_directory_level']
project_file_flag = platform[self.operating_system][u'project_file_flag']
executables = []
for executable in [executable_x32, executable_x64]:
if executable is None:
logging.warning('executable is %s' % executable)
elif os.path.exists(executable):
# print executables
executables.append(executable)
logging.info('executable %s found on this machine.' % executable)
else:
logging.warning('executable %s not found on this machine.' % executable)
tool[u'family'] = family
tool[u'vendor'] = vendor
tool[u'abbreviation'] = abbreviation
tool[u'release_number'] = release_number
tool[u'release_extension'] = release_extension
tool[u'project_template'] = project_template
tool[u'project_workspace_template'] = project_workspace_template
# tool[u'needs_workspace'] = needs_workspace
tool[u'project_directories'] = project_directories_list
tool[u'default_outputs'] = default_outputs
tool[u'architecture_fallback'] = architecture_fallback
tool[u'label_x32'] = label_x32
tool[u'label_x64'] = label_x64
tool[u'project_directories'] = project_directories
tool[u'flags_x32'] = flags_x32
tool[u'flags_x64'] = flags_x64
tool[u'project_workspace_flag'] = project_workspace_flag
tool[u'project_workspace_parent_directory_level'] = project_workspace_parent_directory_level
tool[u'project_file_flag'] = project_file_flag
if executable_x32 in executables:
tool[u'executable_x32'] = executable_x32
else:
tool[u'executable_x32'] = None
if executable_x64 in executables:
tool[u'executable_x64'] = executable_x64
else:
tool[u'executable_x64'] = None
self.tools.append(tool.copy())
# print 'tool', tool
else:
logging.info('source file skipped (reason: disabled): %s' % source_file)
# print self.tools
return self.tools
# @property
# def _outputs(self):
# return self.outputs
# @property
# def _tasks(self):
# return self.tasks
@property
def _tool_items(self):
if not self.tool_items:
# print 'def _tool_items(self):'
for tool in self._tools:
# self.tool_items = []
# for tool in self._tools:
# print tool
index = self._tools.index(tool)
executable = []
# self.run_items = []
if tool[u'executable_x32'] is not None:
executable.append(self._tools[index][u'executable_x32'])
for flag_x32 in self._tools[index][u'flags_x32']:
executable.append(flag_x32)
run_item = self.get_dict_x32(tool)
self.tool_items.append(run_item.copy())
# print run_item
# self.toolsComboBox.addItem(tool[u'label_x32'], run_item.copy())
executable[:] = []
if tool[u'executable_x64'] is not None:
executable.append(self._tools[index][u'executable_x64'])
for flag_x64 in self._tools[index][u'flags_x64']:
executable.append(flag_x64)
run_item = self.get_dict_x64(tool)
self.tool_items.append(run_item.copy())
# print 'run_item', run_item
# self.toolsComboBox.addItem(tool[u'label_x64'], run_item.copy())
executable[:] = []
# print 'self.tool_items', self.tool_items
return self.tool_items
def receive_serialized(self, sock):
# read the length of the data, letter by letter until we reach EOL
length_str = ''
char = sock.recv(1)
# print char
while char != '\n':
length_str += char
# logging.warning('till here')
char = sock.recv(1)
total = int(length_str)
# use a memoryview to receive the data chunk by chunk efficiently
view = memoryview(bytearray(total))
next_offset = 0
while total - next_offset > 0:
recv_size = sock.recv_into(view[next_offset:], total - next_offset)
next_offset += recv_size
try:
deserialized = json.loads(view.tobytes())
# except (TypeError, ValueError), e:
except:
raise Exception('Data received was not in JSON format')
return deserialized
def set_projects_root(self):
logging.info('getting projects_root')
if self.current_platform == 'Windows':
self.set_projects_root_win()
elif self.current_platform == 'Darwin':
self.set_projects_root_darwin()
elif self.current_platform == 'Linux':
self.set_projects_root_linux()
else:
print 'platform not supported'
sys.exit()
def set_projects_root_win(self):
try:
# self.socket.connect((SETTINGS.SERVER_IP, self.serverPort))
# print 'here'
self.socket.sendall('getProjectsRootServerWin')
self.projects_root = self.receive_serialized(self.socket)
logging.info('projectsRootServerWin server successfully queried')
self.server_alive = True
# self.socket.close()
except socket.error:
self.projects_root = SETTINGS.PROJECTS_ROOT_WIN
self.server_alive = False
def set_projects_root_linux(self):
try:
# self.socket.connect((SETTINGS.SERVER_IP, self.serverPort))
# print 'here'
self.socket.sendall('getProjectsRootServerLinux')
self.projects_root = self.receive_serialized(self.socket)
logging.info('projectsRootServerLinux server successfully queried')
self.server_alive = True
# self.socket.close()
except socket.error:
self.projects_root = SETTINGS.PROJECTS_ROOT_LINUX
self.server_alive = False
def set_projects_root_darwin(self):
if self.server_alive == True:
try:
logging.info('sending getProjectsRootServerDarwin to server')
# self.socket.connect((SETTINGS.SERVER_IP, self.serverPort))
# print 'here'
self.socket.sendall('getProjectsRootServerDarwin')
self.projects_root = self.receive_serialized(self.socket)
logging.info('projectsRootServerDarwin server successfully queried')
# self.server_alive = True
# self.socket.close()
except socket.error:
logging.warning('looks like server connection died')
self.projects_root = SETTINGS.PROJECTS_ROOT_DARWIN
self.server_alive = False
else:
if os.path.exists(SETTINGS.PROJECTS_ROOT_DARWIN):
self.projects_root = SETTINGS.PROJECTS_ROOT_DARWIN
elif os.path.exists(SETTINGS.PROJECTS_ROOT_DARWIN_ALT):
self.projects_root = SETTINGS.PROJECTS_ROOT_DARWIN_ALT
else:
logging.warning('no predefinded projects_root found')
def export_to_library_callback(self, node_object):
def callback():
self.export_to_library(node_object)
return callback
def export_to_library(self, node_object):
print 'export_to_library', node_object
date_time = datetime.datetime.now().strftime('%Y-%m-%d_%H%M-%S')
current_dir = os.getcwd()
export_src_node_dir = node_object.location
export_src_node_dir_inputs = os.path.join(export_src_node_dir, 'input')
export_dst_dir_root = self.libraryRoot
export_dst_name = self.getCurrentProject() + SETTINGS.ARCHIVE_SEPARATOR + os.path.basename(os.path.dirname(node_object.getNodeAsset())) + SETTINGS.ARCHIVE_SEPARATOR + os.path.basename(node_object.getNodeAsset()) + SETTINGS.ARCHIVE_SEPARATOR + node_object.label + SETTINGS.ARCHIVE_SEPARATOR + date_time
export_dst_dir = os.path.join(export_dst_dir_root, export_dst_name)
export_dst_name_input = os.path.join(export_dst_dir, 'input')
export_dst_name_output = os.path.join(export_dst_dir, 'output')
os.makedirs(os.path.join(self.libraryRoot, export_dst_name), mode=0777)
os.makedirs(os.path.join(self.libraryRoot, export_dst_name_input), mode=0777)
shutil.copytree(export_src_node_dir_inputs, export_dst_name_output, symlinks=False)
os.chdir(export_dst_dir)
os.symlink(os.path.relpath(export_dst_name_output, export_dst_dir), 'live')
os.path.relpath(export_dst_name_output, export_dst_dir)
os.chdir(current_dir)
def screen_casts_window(self):
if self.screen_casts_window_open is None:
self.screen_casts_ui = ListScreenCastsUI(self, self)
self.screen_casts_ui.show()
self.screen_casts_window_open = self.screen_casts_ui
self.screen_casts_ui.listScreenCastsUIClosed.connect(self.reset_screen_casts_window_open)
else:
self.screen_casts_ui.activateWindow()
self.screen_casts_ui.raise_()
def reset_screen_casts_window_open(self):
# print 'emitted'
self.screen_casts_window_open = None
# def getUser(self):
# return self.user
def _closeEvent(self, event):
if len(self.timeTrackers) > 0 or len(self.screenCasts) > 0 or len(self.qprocesses) > 0:
if len(self.qprocesses) > 0:
qprocesses = []
for qprocess in self.qprocesses:
qprocesses.append(qprocess.pid())
pids = ', '.join([str(qprocess)[:-1] for qprocess in qprocesses])
quit_msg = "Too early to leave. There is still something running...\n\nPID(s): %s" % pids
reply = QMessageBox.critical(self, 'Message', quit_msg, QMessageBox.Ok)
# print 'about to close'
else:
quit_msg = "Are you sure you want to exit PyPELyNE?"
reply = QMessageBox.question(self, 'Message', quit_msg, QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.Yes:
if self.server_alive == True:
logging.info('sending bye')
self.socket.sendall('bye')
# byeMsg = self.receive_serialized(self.socket)[1]
# print byeMsg
logging.info('closing socket')
self.socket.close()
logging.info('socket closed')
self.server_alive = False
event.accept()
else:
event.ignore()
def add_player(self):
self.player_ui = PlayerWidgetUi(self)
self.horizontalLayout.addWidget(self.player_ui)
# self.player_ui.radioButtonPlay.clicked.connect(self.play_audio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.play_audio)
self.player_ui.pushButtonPlayStop.setContextMenuPolicy(Qt.CustomContextMenu)
self.connect(self.player_ui.pushButtonPlayStop, SIGNAL('customContextMenuRequested(const QPoint&)'), self.player_context_menu)
self.player_context_menu = QMenu()
q_menu_titles = []
for dir, subdirs, files in os.walk(SETTINGS.AUDIO_FOLDER_DARWIN, topdown=False):
for file in files:
if file in SETTINGS.EXCLUSIONS:
os.remove(os.path.join(dir, file))
logging.warning('file %s deleted from %s' % (file, dir))
elif os.path.splitext(file)[1] not in SETTINGS.AUDIO_EXTENSIONS:
logging.warning('non audio file %s found in %s' % (file, dir))
else:
if not os.path.relpath(dir, SETTINGS.AUDIO_FOLDER_DARWIN) == '.':
q_menu_name = os.path.relpath(dir, SETTINGS.AUDIO_FOLDER_DARWIN)
# if len(q_menu_name.split(os.sep)) > 1:
if q_menu_name not in q_menu_titles:
self.menuAlbum = self.player_context_menu.addMenu(q_menu_name.replace(os.sep, ' - '))
q_menu_titles.append(q_menu_name)
self.menuAlbum.addAction(file, self.play_audio_callback(os.path.join(dir, file)))
self.audio_folder_content.append(os.path.join(dir, file))
else:
self.menuAlbum.addAction(file, self.play_audio_callback(os.path.join(dir, file)))
self.audio_folder_content.append(os.path.join(dir, file))
else:
self.player_context_menu.addAction(file, self.play_audio_callback(os.path.join(dir, file)))
self.audio_folder_content.append(os.path.join(dir, file))
self.player_ui.pushButtonPlayStop.setText('play')
self.player_exists = False
def player_context_menu(self, point):
self.player_context_menu.exec_(self.player_ui.pushButtonPlayStop.mapToGlobal(point))
def play_audio_callback(self, track=None):
def callback():
self.play_audio(track)
return callback
def play_audio(self, track=None):
# https://forum.videolan.org/viewtopic.php?t=107039
if len(os.listdir(SETTINGS.AUDIO_FOLDER_DARWIN)) == 0:
logging.warning('no audio files found')
self.player_ui.radioButtonPlay.setEnabled(False)
elif not self.player_exists:
random.shuffle(self.audio_folder_content, random.random)
if not track:
print track
track_id = self.audio_folder_content.index(track)
self.mlp = MediaListPlayer()
self.mp = MediaPlayer()
self.mlp.set_media_player(self.mp)
self.ml = MediaList()
for file in self.audio_folder_content:
self.ml.add_media(os.path.join(SETTINGS.AUDIO_FOLDER_DARWIN, file))
self.mlp.set_media_list(self.ml)
if track:
self.mlp.play_item_at_index(track_id)
logging.info('playing %s' % track_id)
else:
self.mlp.play()
logging.info('playing randomly')
self.player_exists = True
self.player_ui.pushButtonPlayStop.clicked.disconnect(self.play_audio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.stopAudio)
self.player_ui.pushButtonPlayStop.setText('stop')
logging.info('setting pushButtonPlayStop function to stop')
threading.Timer(0.5, self.from_stop_to_skip).start()
elif self.player_exists and track:
logging.info('playing %s' % track)
track_id = self.audio_folder_content.index(track)
self.skip_audio(track_id)
else:
logging.info('already on air')
def from_stop_to_skip(self):
if self.player_exists == True:
self.player_ui.pushButtonPlayStop.clicked.disconnect(self.stopAudio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.skip_audio)
self.player_ui.pushButtonPlayStop.setText('skip')
logging.info('setting pushButtonPlayStop function to skip')
def from_skip_to_stop(self):
if self.player_exists == True:
self.player_ui.pushButtonPlayStop.clicked.disconnect(self.skip_audio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.stopAudio)
self.player_ui.pushButtonPlayStop.setText('stop')
logging.info('setting pushButtonPlayStop function to stop')
def stop_audio(self):
if self.player_exists:
try:
self.player_ui.pushButtonPlayStop.clicked.disconnect(self.stopAudio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.play_audio)
self.mp.stop()
self.mp.release()
self.mlp.release()
self.player_exists = False
self.player_ui.pushButtonPlayStop.setText('play')
logging.info('setting pushButtonPlayStop function to play')
#logging.info('audio stopped')
except:
logging.warning('error or not playing')
def skip_audio(self, track_id=None):
if self.player_exists:
if track_id:
self.mlp.play_item_at_index(track_id)
else:
self.mlp.next()
self.player_ui.pushButtonPlayStop.clicked.disconnect(self.skip_audio)
self.player_ui.pushButtonPlayStop.clicked.connect(self.stopAudio)
self.player_ui.pushButtonPlayStop.setText('stop')
threading.Timer(0.5, self.from_stop_to_skip).start()
def compute_value_outputs(self):
self.value_outputs = ET.parse(os.path.join(self.pypelyne_root, 'conf', 'valueOutputs.xml'))
self.value_outputs_root = self.value_outputs.getroot()
self.outputs = []
# categoryList = []
# mimeList = []
item_list = []
for category in self.value_outputs_root:
item_list.append(category.items())
for mime in category:
item_list.append(mime.items())
self.outputs.append(item_list)
item_list = []
@property
def new_process_color(self):
r = random.randint(20, 235)
g = random.randint(20, 235)
b = random.randint(20, 235)
rgb = (QColor(r, g, b))
return rgb
def run_task(self, node_object, executable, args):
new_screen_cast = screenCast(self, os.path.basename(node_object.getNodeAsset()), node_object.label, node_object.project)
new_time_tracker = timeTracker(os.path.basename(node_object.getNodeAsset()), node_object.label, node_object.project)
process = QProcess(self)
process_color = self.new_process_color
# print executable, args
process.readyReadStandardOutput.connect(lambda: self.data_ready_std(process, process_color))
process.readyReadStandardError.connect(lambda: self.dataReadyErr(process, process_color))
process.started.connect(lambda: self.taskOnStarted(node_object, process, new_screen_cast, new_time_tracker))
process.finished.connect(lambda: self.task_on_finished(node_object, process, new_screen_cast, new_time_tracker))
current_dir = os.getcwd()
os.chdir(node_object.getNodeRootDir())
process.start(executable, args)
os.chdir(current_dir)
def check_out_callback(self, node_object):
def callback():
self.check_out(node_object)
return callback
def check_out(self, node_object):
date_time = datetime.datetime.now().strftime('%Y-%m-%d_%H%M-%S')
pigz = os.path.join(self.pypelyne_root, 'payload', 'pigz', 'darwin', 'pigz')
tar_dir_root = os.path.join(self.projects_root, self.getCurrentProject(), 'check_out')
# TODO: refactor
tar_name = date_time + SETTINGS.ARCHIVE_SEPARATOR + self._current_project + SETTINGS.ARCHIVE_SEPARATOR + os.path.basename(os.path.dirname(node_object.getNodeAsset())) + SETTINGS.ARCHIVE_SEPARATOR + os.path.basename(node_object.getNodeAsset()) + SETTINGS.ARCHIVE_SEPARATOR + node_object.label + '.tar.gz'
if not os.path.exists(tar_dir_root):
os.makedirs(tar_dir_root, mode=0777)
arguments = []
arguments.append('cvL')
arguments.append('--exclude')
arguments.append('checkedOut')
#exclude all non-current folders
arguments.append('--exclude')
arguments.append('output/*/2*')
arguments.append('--exclude')
arguments.append('output/*.*')
arguments.append('--exclude')
arguments.append('live')
#arguments.append('--exclude')
#arguments.append('property_node.xml')
arguments.append('--use-compress-program')
arguments.append(pigz)
arguments.append('-f')
arguments.append(os.path.join(tar_dir_root, tar_name))
arguments.append('--directory')
arguments.append(node_object.getNodeRootDir())
arguments.append('.')
process_color = self.new_process_color
process = QProcess(self)
process.readyReadStandardOutput.connect(lambda: self.data_ready_std(process, process_color))
process.readyReadStandardError.connect(lambda: self.dataReadyErr(process, process_color))
process.started.connect(lambda: self.checkOutOnStarted(process))
process.finished.connect(lambda: self.checkoutOnFinished(process, node_object, tar_name))
process.start(self.tar_exec, arguments)
def check_in_callback(self, node_object):
def callback():
self.check_in(node_object)
return callback
def check_in(self, node_object):
try:
check_out_file_path = os.path.join(node_object.location, 'checkedOut')
os.remove(check_out_file_path)
except:
#print 'check in failed'
logging.warning('check in failed')
def taskOnStarted(self, node_object, qprocess, screenCast, timeTracker):
self.qprocesses.append(qprocess)
self.open_nodes.append(node_object)
#print self.qprocesses
logging.info('task %s started' % node_object.label)
lockFilePath = os.path.join(node_object.getNodeRootDir(), 'locked')
lockFile = open(lockFilePath, 'a')
lockFile.write(self.user)
lockFile.close()
#
if SETTINGS.USE_SCREEN_CAST:
screenCast.start()
self.screenCasts.append(screenCast)
self.addNewScreenCast.emit()
timeTracker.start()
self.timeTrackers.append(timeTracker)
def task_on_finished(self, node_object, qprocess, screenCast, timeTracker):
logging.info('task %s finished' % node_object.label)
if SETTINGS.USE_SCREEN_CAST and screenCast in self.screenCasts:
screenCast.stop()
self.screenCasts.remove(screenCast)
self.addNewScreenCast.emit()
timeTracker.stop()
self.timeTrackers.remove(timeTracker)
os.remove(os.path.join(node_object.getNodeRootDir(), 'locked'))
self.open_nodes.remove(node_object)
self.qprocesses.remove(qprocess)
def get_tasks(self):
return self.tasks
def locate_content_callback(self, content_files):
def callback():
self.locate_content(content_files)
return callback
def locate_content(self, content_files):
# print contentFiles
if os.path.exists(content_files):
if self.current_platform == 'Windows':
subprocess.call(self.file_explorer + ' ' + content_files, shell=False)
elif self.current_platform == 'Darwin':
subprocess.Popen([self.file_explorer, content_files], shell=False)
elif self.current_platform == 'Linux':
subprocess.Popen([self.file_explorer, content_files], shell=False)
else:
self.sendTextToBox('platform %s not supported\n' % self.current_platform)
else:
logging.warning('project does not exist:', content_files)