feat: initial export test
This commit is contained in:
parent
f463cb82e7
commit
e62f0682a2
@ -32,6 +32,8 @@ from queue import Queue
|
|||||||
import bpy
|
import bpy
|
||||||
import mathutils
|
import mathutils
|
||||||
from bpy.app.handlers import persistent
|
from bpy.app.handlers import persistent
|
||||||
|
from bpy_extras.io_utils import ExportHelper
|
||||||
|
|
||||||
from replication.constants import (FETCHED, RP_COMMON, STATE_ACTIVE,
|
from replication.constants import (FETCHED, RP_COMMON, STATE_ACTIVE,
|
||||||
STATE_INITIAL, STATE_SYNCING, UP)
|
STATE_INITIAL, STATE_SYNCING, UP)
|
||||||
from replication.data import ReplicatedDataFactory
|
from replication.data import ReplicatedDataFactory
|
||||||
@ -712,6 +714,56 @@ class SessionNotifyOperator(bpy.types.Operator):
|
|||||||
return context.window_manager.invoke_props_dialog(self)
|
return context.window_manager.invoke_props_dialog(self)
|
||||||
|
|
||||||
|
|
||||||
|
class SessionRecordGraphOperator(bpy.types.Operator, ExportHelper):
|
||||||
|
bl_idname = "session.export"
|
||||||
|
bl_label = "SessionRecordGraph"
|
||||||
|
|
||||||
|
# ExportHelper mixin class uses this
|
||||||
|
filename_ext = ".db"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return session.state['STATE'] == STATE_ACTIVE
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
import networkx as nx
|
||||||
|
import pickle
|
||||||
|
import copy
|
||||||
|
|
||||||
|
# Replication graph
|
||||||
|
nodes_ids = session.list()
|
||||||
|
#TODO: add dump graph to replication
|
||||||
|
|
||||||
|
nodes =[]
|
||||||
|
for n in nodes_ids:
|
||||||
|
nd = session.get(uuid=n)
|
||||||
|
nodes.append((
|
||||||
|
n,
|
||||||
|
{
|
||||||
|
'owner': nd.owner,
|
||||||
|
'str_type': nd.str_type,
|
||||||
|
'data': nd.data,
|
||||||
|
'dependencies': nd.dependencies,
|
||||||
|
}
|
||||||
|
))
|
||||||
|
|
||||||
|
G = nx.DiGraph()
|
||||||
|
G.add_nodes_from(nodes)
|
||||||
|
|
||||||
|
for n, nd in nodes:
|
||||||
|
relations = [(n,d) for d in nd['dependencies']]
|
||||||
|
G.add_edges_from(relations)
|
||||||
|
|
||||||
|
|
||||||
|
# Users
|
||||||
|
G.graph['users'] = copy.copy(session.online_users)
|
||||||
|
|
||||||
|
with open(self.filepath, "wb") as f:
|
||||||
|
pickle.dump(G, f, protocol=4)
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
SessionStartOperator,
|
SessionStartOperator,
|
||||||
SessionStopOperator,
|
SessionStopOperator,
|
||||||
@ -726,6 +778,7 @@ classes = (
|
|||||||
SessionInitOperator,
|
SessionInitOperator,
|
||||||
SessionClearCache,
|
SessionClearCache,
|
||||||
SessionNotifyOperator,
|
SessionNotifyOperator,
|
||||||
|
SessionRecordGraphOperator,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -550,6 +550,7 @@ class SESSION_PT_repository(bpy.types.Panel):
|
|||||||
|
|
||||||
def draw_header(self, context):
|
def draw_header(self, context):
|
||||||
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')
|
self.layout.label(text="", icon='OUTLINER_OB_GROUP_INSTANCE')
|
||||||
|
self.layout.operator('session.export',text="", icon="EXPORT")
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user