def mkdirSudo(path, sudoFound=None, flagStr=''): """sudo is not avail on all plats, so su root on other nixes""" if os.name == 'posix': if sudoFound == None: # test sudoFound = drawer.isSudo() # 1 if exists if drawer.isDarwin() or sudoFound: print PROMPTdarwin % ('writing directory', path) os.system('sudo mkdir %s %s' % (flagStr, path)) else: # other *nixes print PROMPTposix % ('writing directory', path) os.system('su root -c "mkdir %s %s"' % (flagStr, path)) else: os.mkdir(path)
def chmodSudo(value, path, sudoFound=None): """sudo is not avail on all plats, so su root on other nixes""" if os.name == 'posix': if not drawer.isStr(value): value = str(value) if sudoFound == None: # test sudoFound = drawer.isSudo() # 1 if exists if drawer.isDarwin() or sudoFound: print PROMPTdarwin % ('changing permissions', path) os.system('sudo chmod %s "%s"' % (value, path)) else: # other *nixes print PROMPTposix % ('changing permissions', path) os.system('su root -c "chmod %s %s"' % (value, path))
def mvSudo(src, dst, sudoFound=None): """sudo is not avail on all plats, so su root on other nixes""" if os.name == 'posix': if sudoFound == None: # test sudoFound = drawer.isSudo() # 1 if exists if drawer.isDarwin() or sudoFound: print PROMPTdarwin % ('moving', dst) os.system('sudo mv %s %s' % (src, dst)) else: # other *nixes print PROMPTposix % ('moving', dst) os.system('su root -c "mv %s %s"' % (src, dst)) else: # mac, windows shutil.move(src, dst)
def cpSudo(src, dst, sudoFound=None): """sudo is not avail on all plats, so su root on other nixes""" if os.name == 'posix': if sudoFound == None: # test sudoFound = drawer.isSudo() # 1 if exists if drawer.isDarwin() or sudoFound: print PROMPTdarwin % ('writing', dst) os.system('sudo cp %s %s' % (src, dst)) else: # other *nixes print PROMPTposix % ('writing', dst) os.system('su root -c "cp %s %s"' % (src, dst)) else: # mac, windows if os.path.isdir(): shutil.copytree(src, dst) else: # assume a file shutil.copyfile(src, dst)
def rmSudo(path, sudoFound=None): """sudo is not avail on all plats, so su root on other nixes""" if path == os.sep: raise ValueError, 'macro remove canceled' # safety if os.name == 'posix': if sudoFound == None: # test sudoFound = drawer.isSudo() # 1 if exists if drawer.isDarwin() or sudoFound: print PROMPTdarwin % ('removing', path) os.system('sudo rm -f -r "%s"' % path) else: # other *nixes print PROMPTposix % ('removing', path) os.system('su root -c "rm -f -r %s"' % path) else: # mac, windows for root, dirs, files in os.walk(path, topdown=False): for name in files: os.remove(os.path.join(root, name)) for name in dirs: os.rmdir(os.path.join(root, name)) os.rmdir(path)
def openMedia(path, prefDict=None): """open a media or text file, file type is determined by extension will assume that path is to a media file, rather than an exe for executable scripts, use launch if prefDict is provided, will get app path from there keys in this disc must start w/ media type; image, audio, midi, text, ps TODO: this should be updated to use application preferences stored in prefTools.py, not here """ path = drawer.pathScrub(path) dir, name = os.path.split(path) name, ext = extSplit(name) # this should be as method of a the pref tools # pref object/dict, or a function in this module or drawer if ext in imageEXT: fileType = 'image' elif ext in audioEXT: fileType = 'audio' elif ext in videoEXT: fileType = 'video' elif ext in midiEXT: fileType = 'midi' elif ext in textEXT or ext in codeEXT: fileType = 'text' elif ext in psEXT: fileType = 'ps' else: fileType = None app = None # default nothing if prefDict == None and fileType != None: # get default apps # if os.name == 'mac': pass # rely on system if os.name == 'posix': if drawer.isDarwin(): # assume sys default for most if fileType in ['audio', 'midi', 'video']: app = '/Applications/QuickTime Player.app' else: # other unix if fileType == 'text': app = 'more' elif fileType == 'audio': app = 'xmms' #'play' should work too elif fileType == 'midi': app = 'playmidi' # elif fileType == 'image': app = 'imagemagick' elif fileType == 'ps': app = 'gs' else: # win or other pass # rely on system elif fileType != None: # get from prefDict for key in prefDict.keys(): # match by filetype string leading key and path string if key.startswith(fileType) and 'path' in key.lower(): app = prefDict[key] # may be a complete file path, or a name if app == '': app = None # if given as empty, convert to none elif not drawer.isApp(app): app = None # if not an app any more, drop # if os.name == 'mac': # os9 # cmdExe = '%s' % path # on mac, just launch txt file, rely on pref if os.name == 'posix': if drawer.isDarwin(): if app == None: # no app use system default cmdExe = 'open "%s"' % path elif app.lower().endswith('.app'): # if a .app type app cmdExe = 'open -a "%s" "%s"' % (app, path) else: # its a unix style command cmdExe = '%s %s' % (app, path) else: # other unix if app == None: cmdExe = '%s' % (path) else: cmdExe = '%s %s' % (app, path) else: # win or other, rely on system settings cmdExe = '%s' % path # on win, just launch path return launch(cmdExe) # returns None on success
def getCategoryDefaultDict(platform, category): """ default preference dictionaries loaded whem pref.xml missing or used to update old pref file. gets only a single catgegory for platform note: external prefs are read by osTools.openMedia by key value; it is necessary that keys start with the appropriate format strings >>> a = getCategoryDefaultDict('win', 'external') >>> a['audioFormat'] 'wav' >>> a = getCategoryDefaultDict('win', 'athena') >>> a['dlgVisualMethod'] 'text' >>> a['gfxVisualMethod'] 'tk' >>> a = getCategoryDefaultDict('posix', 'athena') >>> a['dlgVisualMethod'] 'text' >>> a['gfxVisualMethod'] 'png' """ # common to all, some may be chagned in patform specific below if category == 'external': catDict = { 'audioFormat': 'aif', # this is a csound opt 'autoRenderOption': 'autoOff', # this is a csound opt 'csoundPath': '', # should be name csoundCommand... 'midiPlayerPath': '', 'audioPlayerPath': '', 'textReaderPath': '', 'imageViewerPath': '', 'psViewerPath': '', } if category == 'athena': catDict = { 'fpLastDir': '', 'fpLastDirEventList': '', 'fpScratchDir': '', # used for writing temporary files 'fpAudioDir': '', 'tLastVersionCheck': '', 'eventOutput': "('midiFile', 'xmlAthenaObject', 'csoundData')", 'eventMode': 'midi', # startup value 'refreshMode': '1', # esObj refreshing 'debug': '0', 'cursorToolLb': '', 'cursorToolRb': '', 'cursorToolLp': '{', 'cursorToolRp': '}', 'cursorToolP': 'pi', 'cursorToolT': 'ti', 'cursorToolOption': 'cursorToolOn', } if category == 'gui': catDict = { 'COLORfgAbs': '#808080', #128,128,128 'COLORfgMain': '#505050', #80,80,80 'COLORfgMainFrame': '#6E6E6E', #110,110,110 'COLORfgAlt': '#3C3C3C', #60,60,60 'COLORfgAltFrame': '#5A5A5A', #90,90,90 'COLORbgMargin': '#2A2A2A', #42,42,42 'COLORbgGrid': '#202020', #32,32,32 'COLORbgAbs': '#000000', #backmost 'COLORtxTitle': '#9F9F9F', #'#9A9A9A', #154,154,154 'COLORtxLabel': '#7C7C7C', #124,124,124 'COLORtxUnit': '#8A7A6A', #138,122,106 } if platform == 'posix': if drawer.isDarwin(): if category == 'external': catDict['csoundPath'] = '/usr/local/bin/csound' catDict[ 'midiPlayerPath'] = '/Applications/QuickTime Player.app' catDict[ 'audioPlayerPath'] = '/Applications/QuickTime Player.app' catDict['textReaderPath'] = '' # will use system default catDict['imageViewerPath'] = '/Applications/Preview.app' catDict['psViewerPath'] = '/Applications/Preview.app' else: if category == 'external': catDict['csoundPath'] = '/usr/local/bin/csound' catDict['midiPlayerPath'] = 'playmidi' catDict['audioPlayerPath'] = 'xmms' catDict['textReaderPath'] = 'more' # will use system default catDict['imageViewerPath'] = 'imagemagick' catDict['psViewerPath'] = 'gs' # common for all posix if category == 'athena': catDict['dlgVisualMethod'] = 'text' catDict['gfxVisualMethod'] = 'png' # return to pil else: # win or other if category == 'external': catDict['audioFormat'] = 'wav' if category == 'athena': catDict[ 'dlgVisualMethod'] = 'text' # works w/n idle, console on win catDict['gfxVisualMethod'] = 'tk' return catDict
def openMedia(path, prefDict=None): """open a media or text file, file type is determined by extension will assume that path is to a media file, rather than an exe for executable scripts, use launch if prefDict is provided, will get app path from there keys in this disc must start w/ media type; image, audio, midi, text, ps TODO: this should be updated to use application preferences stored in prefTools.py, not here """ path = drawer.pathScrub(path) dir, name = os.path.split(path) name, ext = extSplit(name) # this should be as method of a the pref tools # pref object/dict, or a function in this module or drawer if ext in imageEXT: fileType = 'image' elif ext in audioEXT: fileType = 'audio' elif ext in videoEXT: fileType = 'video' elif ext in midiEXT: fileType = 'midi' elif ext in textEXT or ext in codeEXT: fileType = 'text' elif ext in psEXT: fileType = 'ps' else: fileType = None app = None # default nothing if prefDict == None and fileType != None: # get default apps # if os.name == 'mac': pass # rely on system if os.name == 'posix': if drawer.isDarwin(): # assume sys default for most if fileType in ['audio', 'midi', 'video']: app = '/Applications/QuickTime Player.app' else: # other unix if fileType == 'text' : app = 'more' elif fileType == 'audio': app = 'xmms' #'play' should work too elif fileType == 'midi' : app = 'playmidi' # elif fileType == 'image': app = 'imagemagick' elif fileType == 'ps': app = 'gs' else: # win or other pass # rely on system elif fileType != None: # get from prefDict for key in prefDict.keys(): # match by filetype string leading key and path string if key.startswith(fileType) and 'path' in key.lower(): app = prefDict[key] # may be a complete file path, or a name if app == '': app = None # if given as empty, convert to none elif not drawer.isApp(app): app = None # if not an app any more, drop # if os.name == 'mac': # os9 # cmdExe = '%s' % path # on mac, just launch txt file, rely on pref if os.name == 'posix': if drawer.isDarwin(): if app == None: # no app use system default cmdExe = 'open "%s"' % path elif app.lower().endswith('.app'): # if a .app type app cmdExe = 'open -a "%s" "%s"' % (app, path) else: # its a unix style command cmdExe = '%s %s' % (app, path) else: # other unix if app == None: cmdExe = '%s' % (path) else: cmdExe = '%s %s' % (app, path) else: # win or other, rely on system settings cmdExe = '%s' % path # on win, just launch path return launch(cmdExe) # returns None on success
def getCategoryDefaultDict(platform, category): """ default preference dictionaries loaded whem pref.xml missing or used to update old pref file. gets only a single catgegory for platform note: external prefs are read by osTools.openMedia by key value; it is necessary that keys start with the appropriate format strings >>> a = getCategoryDefaultDict('win', 'external') >>> a['audioFormat'] 'wav' >>> a = getCategoryDefaultDict('win', 'athena') >>> a['dlgVisualMethod'] 'text' >>> a['gfxVisualMethod'] 'tk' >>> a = getCategoryDefaultDict('posix', 'athena') >>> a['dlgVisualMethod'] 'text' >>> a['gfxVisualMethod'] 'png' """ # common to all, some may be chagned in patform specific below if category == 'external': catDict = { 'audioFormat': 'aif', # this is a csound opt 'autoRenderOption': 'autoOff', # this is a csound opt 'csoundPath': '', # should be name csoundCommand... 'midiPlayerPath': '', 'audioPlayerPath': '', 'textReaderPath': '', 'imageViewerPath': '', 'psViewerPath': '', } if category == 'athena': catDict = { 'fpLastDir': '', 'fpLastDirEventList': '', 'fpScratchDir': '', # used for writing temporary files 'fpAudioDir': '', 'tLastVersionCheck': '', 'eventOutput': "('midiFile', 'xmlAthenaObject', 'csoundData')", 'eventMode':'midi', # startup value 'refreshMode': '1', # esObj refreshing 'debug': '0', 'cursorToolLb': '', 'cursorToolRb': '', 'cursorToolLp': '{', 'cursorToolRp': '}', 'cursorToolP' : 'pi', 'cursorToolT' : 'ti', 'cursorToolOption': 'cursorToolOn', } if category == 'gui': catDict = {'COLORfgAbs': '#808080', #128,128,128 'COLORfgMain': '#505050', #80,80,80 'COLORfgMainFrame': '#6E6E6E', #110,110,110 'COLORfgAlt': '#3C3C3C', #60,60,60 'COLORfgAltFrame': '#5A5A5A', #90,90,90 'COLORbgMargin': '#2A2A2A', #42,42,42 'COLORbgGrid': '#202020', #32,32,32 'COLORbgAbs': '#000000', #backmost 'COLORtxTitle': '#9F9F9F', #'#9A9A9A', #154,154,154 'COLORtxLabel': '#7C7C7C', #124,124,124 'COLORtxUnit': '#8A7A6A', #138,122,106 } if platform == 'posix': if drawer.isDarwin(): if category == 'external': catDict['csoundPath'] = '/usr/local/bin/csound' catDict['midiPlayerPath'] = '/Applications/QuickTime Player.app' catDict['audioPlayerPath'] = '/Applications/QuickTime Player.app' catDict['textReaderPath'] = '' # will use system default catDict['imageViewerPath'] = '/Applications/Preview.app' catDict['psViewerPath'] = '/Applications/Preview.app' else: if category == 'external': catDict['csoundPath'] = '/usr/local/bin/csound' catDict['midiPlayerPath'] = 'playmidi' catDict['audioPlayerPath'] = 'xmms' catDict['textReaderPath'] = 'more' # will use system default catDict['imageViewerPath'] = 'imagemagick' catDict['psViewerPath'] = 'gs' # common for all posix if category == 'athena': catDict['dlgVisualMethod'] = 'text' catDict['gfxVisualMethod'] = 'png' # return to pil else: # win or other if category == 'external': catDict['audioFormat'] = 'wav' if category == 'athena': catDict['dlgVisualMethod'] = 'text' # works w/n idle, console on win catDict['gfxVisualMethod'] = 'tk' return catDict