feat: initial export test
This commit is contained in:
@ -32,6 +32,8 @@ from queue import Queue
|
||||
import bpy
|
||||
import mathutils
|
||||
from bpy.app.handlers import persistent
|
||||
from bpy_extras.io_utils import ExportHelper
|
||||
|
||||
from replication.constants import (FETCHED, RP_COMMON, STATE_ACTIVE,
|
||||
STATE_INITIAL, STATE_SYNCING, UP)
|
||||
from replication.data import ReplicatedDataFactory
|
||||
@ -712,6 +714,56 @@ class SessionNotifyOperator(bpy.types.Operator):
|
||||
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 = (
|
||||
SessionStartOperator,
|
||||
SessionStopOperator,
|
||||
@ -726,6 +778,7 @@ classes = (
|
||||
SessionInitOperator,
|
||||
SessionClearCache,
|
||||
SessionNotifyOperator,
|
||||
SessionRecordGraphOperator,
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user