def pruneTabDirectories(self, workspace): with open(os.path.join(workspace, 'order.yml'), 'r') as stream: order = yaml.load(stream)['order'] for entry in os.listdir(workspace): fullPath = os.path.join(workspace, entry) if os.path.isfile(fullPath): continue if entry not in order: log('DEBUG', 'removing', fullPath) shutil.rmtree(fullPath)
def __init__(self, configDir=None): if configDir == None: self.configDir = os.path.join( os.path.dirname(os.path.realpath(sys.argv[0])), 'nodes/' ) else: self.configDir = configDir if os.path.isfile(self.configDir): sys.stderr.write('Config directory is a file\n') sys.exit(1) if not os.path.exists(self.configDir): log('INFO', 'Directory {0} not found. Creating...'.format(self.configDir)) os.mkdir(self.configDir)
def commit(self, stateObject, palette, workspaceName): """Write stateObject to layout.yml files""" order = [] writtenTabs = [] workspace = os.path.join(self.configDir, workspaceName) for objectIndex, obj in enumerate(stateObject["objects"]): writeObj = {} log('DEBUG', 'Working on', obj) for circle in obj["circles"]: nodeDetails = { 'image': circle['image'], 'radius': circle['r'], 'position': [circle['x'],circle['y']], 'colors': [circle['style']['inColor'], circle['style']['outColor']] } if 'network' in circle: nodeDetails['network'] = circle['network'] writeObj[circle['label']] = nodeDetails for path in obj['paths']: if 'links' not in writeObj[path['from']]: writeObj[path['from']]['links'] = [] writeObj[path['from']]['links'].append(path['to']) tabName = stateObject['tabs'][objectIndex]['name'] order.append(tabName) tabDir = os.path.join(workspace, tabName) if not os.path.isdir(tabDir): os.mkdir(tabDir) layoutFile = os.path.join(tabDir, 'layout.yml') with open(layoutFile, 'w') as stream: yaml.dump(writeObj, stream) writtenTabs.append(tabName) orderFile = os.path.join(workspace, 'order.yml') with open(orderFile, 'w') as stream: yaml.dump({"order":order}, stream) paletteFile = os.path.join(workspace, 'palette.yml') with open(paletteFile, 'w') as stream: yaml.dump(palette, stream) self.pruneTabDirectories(workspace)