def ParseConfigFile(): global FILES_DIR global THUMB_DIR global dirHash global types global viewers # reinitialize everything FILES_DIR = "" THUMB_DIR = "" dirHash = {} types = {} viewers = {} # read the config file f = open(CONFIG_FILE, "r") for line in f: line = line.strip() if line.startswith("FILES_DIR"): FILES_DIR = line.split("=")[1].strip() if not os.path.isabs(FILES_DIR): FILES_DIR = getUserPath("fileServer", FILES_DIR) FILES_DIR = os.path.realpath(FILES_DIR) #expand any symbolic links in the library directory THUMB_DIR = opj(FILES_DIR, "thumbnails") elif line.startswith("type:"): line = line.split(":",1)[1] (type, extensions) = line.split("=") types[type.strip()] = extensions.strip().split(" ") dirHash[type.strip()] = opj(FILES_DIR, type.strip()) elif line.startswith("app:"): line = line.split(":", 1)[1].strip() (type, app) = line.split("=") tpl = app.strip().split(" ", 1) if len(tpl) == 1: params = "" else: params = tpl[1].strip() app = tpl[0].strip() viewers[type.strip()] = (app, params) f.close() # create the folders first if they dont exist if not os.path.isdir(FILES_DIR): os.makedirs(FILES_DIR) if not os.path.isdir(CACHE_DIR): os.makedirs(CACHE_DIR) for fileType, typeDir in dirHash.items(): if not os.path.isdir( ConvertPath(typeDir) ): os.makedirs(typeDir) if not os.path.isdir( ConvertPath( opj(typeDir, "Trash")) ): os.makedirs( opj(typeDir, "Trash") ) if fileType == "image" and not os.path.isdir( ConvertPath( opj(typeDir, "screenshots")) ): os.makedirs( opj(typeDir, "screenshots") ) if not os.path.isdir(THUMB_DIR): os.makedirs(THUMB_DIR)
def WriteLog(text): if REDIRECT: try: logFile = open(getUserPath("applications","output.txt"), "a") logFile.write( text+"\n" ) logFile.flush() #flush the buffer to a file (especially needed if running as a daemon) logFile.close() except: pass else: print text
def ParseConfigFile(): global FILES_DIR global THUMB_DIR global dirHash global types global viewers # reinitialize everything FILES_DIR = "" THUMB_DIR = "" dirHash = {} types = {} viewers = {} # read the config file f = open(CONFIG_FILE, "r") for line in f: line = line.strip() if line.startswith("FILES_DIR"): FILES_DIR = line.split("=")[1].strip() if not os.path.isabs(FILES_DIR): FILES_DIR = getUserPath("fileServer", FILES_DIR) FILES_DIR = os.path.realpath( FILES_DIR) #expand any symbolic links in the library directory THUMB_DIR = opj(FILES_DIR, "thumbnails") elif line.startswith("type:"): line = line.split(":", 1)[1] (type, extensions) = line.split("=") types[type.strip()] = extensions.strip().split(" ") dirHash[type.strip()] = opj(FILES_DIR, type.strip()) elif line.startswith("app:"): line = line.split(":", 1)[1].strip() (type, app) = line.split("=") tpl = app.strip().split(" ", 1) if len(tpl) == 1: params = "" else: params = tpl[1].strip() app = tpl[0].strip() viewers[type.strip()] = (app, params) f.close() # create the folders first if they dont exist if not os.path.isdir(FILES_DIR): os.makedirs(FILES_DIR) if not os.path.isdir(CACHE_DIR): os.makedirs(CACHE_DIR) for type, typeDir in dirHash.items(): if not os.path.isdir(ConvertPath(typeDir)): os.makedirs(typeDir) if not os.path.isdir(ConvertPath(opj(typeDir, "Trash"))): os.makedirs(opj(typeDir, "Trash")) if not os.path.isdir(THUMB_DIR): os.makedirs(THUMB_DIR)
def __init__(self, name, appName, dynamic=False): self._configName = name self._dynamic = dynamic # dynamic config??? self._appName = appName self._configFilename = getUserPath("applications", appName+".conf") self._launcherId = "" self._binDir = "$SAGE_DIRECTORY/bin/" # where the binary resides - this is where the config is copied to self._nodeNum = 1 self._position = (100, 100) # initial position of the window on SAGE self._size = (-1, -1) # initial size of the window on SAGE self._command = "" # the actual command used to start the application self._targetMachine = "" # the render machine where the app will be started self._protocol = "TCP" self._masterIP = None # the master machine of a parallel application self._fsIP = None # which SAGE will the app connect to (if not using sageBridge) self._fsPort = None # which SAGE will the app connect to (if not using sageBridge) self._useBridge = False # if True the app will connect to sageBridge instead of fsManager self._bridgeIP = "" # the machine for sage bridge self._bridgePort = "" # the machine for sage bridge self._additionalParams = "" # any additional parameters you want to specify... used for testing # audio stuff self._audioFile = "" self._framePerBuffer = 512 self._nwID = 1 self._msgPort = 23010 self._syncPort = 13010 self._nodeNum = 1 self._appId = 0 # the port number for the app on the render machine self._blockSize = (64,64) self._blockThreshold = 0 self._streamType = "SAGE_BLOCK_HARD_SYNC" # sync mode self._staticApp = False # static applications dont refresh their windows so sage needs to keep the last frame self._runOnNodes = False # if an app has to connect to the outside world or requires
sys.path.append("misc") #so that we can import packages from "misc" folder from imsize import imagesize # reads the image header and gets the size from it import mmpython import countPDFpages # a shortcut opj = os.path.join # for loading the sagePath helper file sys.path.append(opj(os.environ["SAGE_DIRECTORY"], "bin")) from sagePath import getUserPath, getPath ## some globals defining the environment SCRIPT_PATH = sys.path[0] CONFIG_FILE = getPath("fileServer", "fileServer.conf") CACHE_DIR = getUserPath("fileServer", "file_server_cache") FILES_DIR = opj(SCRIPT_PATH, "file_library") REDIRECT = False THUMB_DIR = opj(FILES_DIR, "thumbnails") RUN_SERVER = True ## holds information about the types that we support (read from the config file) dirHash = {} viewers = {} types = {} def ParseConfigFile(): global FILES_DIR global THUMB_DIR global dirHash
result = config.getfloat(section, key) elif isinstance(result, int): result = config.getint(section, key) else: result = config.get(section, key) return result # shortcut opj = os.path.join sys.path.append( opj(os.environ["SAGE_DIRECTORY"], "bin" ) ) from sagePath import getUserPath, SAGE_DIR, getPath # commonly used paths SAVED_STATES_DIR = getUserPath("saved-states") FS_CONFIG_FILE = getPath("fsManager.conf") FILE_SERVER_PORT = "8800" # play sounds or not... CAN_PLAY_SOUND = False # types of overlay plugins UI_PLUGIN = 0 # contains multiple widgets... WIDGET_PLUGIN = 1 # a single widget, loaded automatically or through UI_PLUGIN # configuration file for DIM
# Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum # # Author: Ratko Jagodic # ############################################################################ ### MODULE FOR SAVING SAGE UI PREFERENCES ### import os, os.path, cPickle, copy, sys from globals import * from sagePath import getUserPath # where we store all the prefs PREFS_DIR = getUserPath("sageui", "prefs") FILE_LIB_FILE = opj(PREFS_DIR, "file_libs.pickle") USERNAMES_FILE = opj(PREFS_DIR, "usernames.pickle") VISUAL_FILE = opj(PREFS_DIR, "visuals.pickle") FAVORITES_FILE = opj(PREFS_DIR, "favorite_files.pickle") MACHINES_FILE = opj(PREFS_DIR, "machines.pickle") VNC_FILE = opj(PREFS_DIR, "vnc.pickle") global fileLib global usernames global visual global favorite_files global machines global vnc
perfButtonColor = wx.Colour(0, 153, 153) perfButtonTextColor = wx.Colour(255, 255, 255) perfPanelColor = wx.Colour(102,204,153) #------------------------------------------------------------------------ # PATHS #------------------------------------------------------------------------ def ConvertPath(path): """Convert paths to the platform-specific separator""" return apply(opj, tuple(path.split('\\'))) DATA_DIR = getUserPath("sageui", "data") LOG_FILE = getUserPath("sageui", "output_log.txt") SAVED_STATES_DIR = getUserPath("saved-states") #------------------------------------------------------------------------ # DIALOG UTILITY FUNCTIONS #------------------------------------------------------------------------ def ShowWriteFailedDialog(filename): dialog = wx.MessageDialog(None, "Unable to write to file <"+filename+">. Check write permissions for the file or directory.", "Write Failed", wx.OK) dialog.ShowModal() def Message(msg, title):
from imsize import imagesize # reads the image header and gets the size from it import mmpython import countPDFpages # a shortcut opj = os.path.join # for loading the sagePath helper file sys.path.append( opj(os.environ["SAGE_DIRECTORY"], "bin" ) ) from sagePath import getUserPath, getPath ## some globals defining the environment SCRIPT_PATH = sys.path[0] CONFIG_FILE = getPath("fileServer", "fileServer.conf") CACHE_DIR = getUserPath("fileServer", "file_server_cache") FILES_DIR = opj(SCRIPT_PATH, "file_library") REDIRECT = False THUMB_DIR = opj(FILES_DIR, "thumbnails") RUN_SERVER = True ## holds information about the types that we support (read from the config file) dirHash = {} viewers = {} types = {} def ParseConfigFile(): global FILES_DIR global THUMB_DIR global dirHash
def setConfigFilename(self): appName = self._appName if appName == "imageviewer" or appName == "pdfviewer" or appName=="mplayer" or appName=="VNCViewer": tf = tempfile.mkstemp(prefix=appName, dir=getUserPath("applications", "conf")) self._configFilename = tf[1]