def moveFileToDest(local_path, destination): import os, shutil from printMessage import printMessage if destination[0] != '/': destination = os.path.abspath(os.path.join(workingDir, destination)) printMessage('Moving output file from temporary directory to user specified location') shutil.move(local_path, destination)
def delTempDir(temp_dir, verbose): import shutil from printMessage import printMessage if verbose: printMessage("Deleting temporary directory " + temp_dir) shutil.rmtree(temp_dir)
def getHeaderInfo(image_path, header_item, verbose): import os, subprocess, sys from printMessage import printMessage command = 'mrinfo ' + image_path + ' -' + header_item if verbose: printMessage('Command: \'' + command + '\' (piping data to local storage)') proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True) result = proc.stdout.read() result = result.rstrip() if verbose: printMessage ('Result: ' + result) return result
def getHeaderInfo(image_path, header_item): import app, os, subprocess, sys from printMessage import printMessage command = 'mrinfo ' + image_path + ' -' + header_item if app.verbosity > 1: printMessage('Command: \'' + command + '\' (piping data to local storage)') proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True) result = proc.stdout.read() result = result.rstrip() if app.verbosity > 1: printMessage ('Result: ' + result) return result
def initialise(n): import os, random, string, sys from printMessage import printMessage from readMRtrixConfSetting import readMRtrixConfSetting global cleanup, mrtrixQuiet, numArgs, tempDir, verbosity, workingDir #if not numArgs: # sys.stderr.write('Must set numArgs value before calling initialise()\n') # exit(1) numArgs = n workingDir = os.getcwd() for option in sys.argv[numArgs+1:]: if '-verbose'.startswith(option): verbosity = 2 mrtrixQuiet = '' elif '-quiet'.startswith(option): verbosity = 0 mrtrixQuiet = '-quiet' elif '-nocleanup'.startswith(option): cleanup = False else: sys.stderr.write('Unknown option: ' + option + '\n') exit(1) # Create the temporary directory dir_path = readMRtrixConfSetting('TmpFileDir') if not dir_path: if os.name == 'posix': dir_path = '/tmp' else: dir_path = '.' prefix = readMRtrixConfSetting('TmpFilePrefix') if not prefix: prefix = os.path.basename(sys.argv[0]) + '-tmp-' tempDir = dir_path while os.path.isdir(tempDir): random_string = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6)) tempDir = os.path.join(dir_path, prefix + random_string) + os.sep os.makedirs(tempDir) printMessage('Generated temporary directory: ' + tempDir)
def terminate(): import os, shutil from printMessage import printMessage printMessage('Changing back to original directory (' + workingDir + ')') os.chdir(workingDir) if cleanup: printMessage('Deleting temporary directory ' + tempDir) shutil.rmtree(tempDir) else: printMessage('Contents of temporary directory kept, location: ' + tempDir)
def delTempDir(temp_dir, verbose): import shutil from printMessage import printMessage if verbose: printMessage('Deleting temporary directory ' + temp_dir) shutil.rmtree(temp_dir)
def gotoTempDir(): import os from printMessage import printMessage if verbosity: printMessage('Changing to temporary directory (' + tempDir + ')') os.chdir(tempDir)