def mergeApp(appName): appPath = _getAppPath(appName, True) if not appPath: return None tmpPath = os.path.join(PACKAGE_PATH, 'DELETEME_' + appName) # this should copy app dir to tmp dir bundle_paths.maybe_makedirs(tmpPath) comm.mergeDirs(appPath, tmpPath) localPath = os.path.join(tmpPath, 'local') defaultPath = os.path.join(tmpPath, 'default') # check if the app is allowed to be merged if os.path.exists(localPath) and os.path.exists(defaultPath): # merge local and default dirs in tmp, result in local b = bundle_paths.Bundle('dummy', 'bundle') comm.mergeDirs(defaultPath, localPath, False, b._merger) # remove default bundle_paths.safe_remove(defaultPath) # move local to default comm.moveItem(localPath, defaultPath) return tmpPath
def mergeApp(appName): appPath = _getAppPath(appName, True) if not appPath: return None tmpPath = os.path.join(PACKAGE_PATH, 'DELETEME_' + appName) # this should copy app dir to tmp dir bundle_paths.maybe_makedirs(tmpPath) comm.mergeDirs(appPath, tmpPath) localPath = os.path.join(tmpPath, 'local') defaultPath = os.path.join(tmpPath, 'default') # check if the app is allowed to be merged if os.path.exists(localPath) and os.path.exists(defaultPath): # merge local and default dirs in tmp, result in local b = bundle_paths.Bundle('dummy', 'bundle') comm.mergeDirs(defaultPath, localPath, False, b._merger) # remove default bundle_paths.safe_remove(defaultPath) # move local to default comm.moveItem(localPath, defaultPath) return tmpPath
def createApp(appName, template, **kwargs): appPath = _getAppPath(appName) if os.path.exists(appPath): raise admin.AlreadyExistsException( _("App '%s' already exists. Nothing was created.") % appName) if template not in getTemplates(): raise admin.ArgValidationException( _("Template '%s' does not exist.") % template) # Make sure we don't mess the app.conf file - add a backslash at the eol kwargs['description'] = kwargs['description'].replace('\n', '\\\n') # Generate files for the app bundle_paths.maybe_makedirs(appPath) os.chdir(appPath) templatePath = os.path.join(TEMPLATES_PATH, template) for root, dirs, files in os.walk(templatePath): # determine relative path relPath = root[len(templatePath) + 1:] # create subdirs for dir in dirs: bundle_paths.maybe_makedirs(os.path.join(relPath, dir)) # Read template files and apply param values then save for fn in files: try: # use params to create custom file names inFilePath = os.path.join(root, fn) # filter by file type fn, isText = _isTextFile(fn) outFilePath = os.path.join(appPath, relPath, fn) if not isText: comm.copyItem(inFilePath, outFilePath) continue with open(inFilePath, 'r') as f_in: content = f_in.read() content = SafeTemplate(content).substitute(kwargs) with open(outFilePath, 'w') as f_out: f_out.write(content) except: print traceback.print_exc(file=sys.stderr) pass return '%s/app/%s' % (_getSplunkWebUri(), appName)
def createApp(appName, template, **kwargs): appPath = _getAppPath(appName) if os.path.exists(appPath): raise admin.AlreadyExistsException(_("App '%s' already exists. Nothing was created.") % appName) if template not in getTemplates(): raise admin.ArgValidationException(_("Template '%s' does not exist.") % template) # Make sure we don't mess the app.conf file - add a backslash at the eol kwargs['description'] = kwargs['description'].replace('\n', '\\\n') # Generate files for the app bundle_paths.maybe_makedirs(appPath) os.chdir(appPath) templatePath = os.path.join(TEMPLATES_PATH, template) for root, dirs, files in os.walk(templatePath): # determine relative path relPath = root[len(templatePath)+1:] # create subdirs for dir in dirs: bundle_paths.maybe_makedirs(os.path.join(relPath,dir)) # Read template files and apply param values then save for fn in files: try: # use params to create custom file names inFilePath = os.path.join(root, fn) # filter by file type fn, isText = _isTextFile(fn) outFilePath = os.path.join(appPath, relPath, fn) if not isText: comm.copyItem(inFilePath, outFilePath) continue with open(inFilePath, 'r') as f_in: content = f_in.read() content = SafeTemplate(content).substitute(kwargs) with open(outFilePath, 'w') as f_out: f_out.write(content) except: print traceback.print_exc(file=sys.stderr) pass return '%s/app/%s' % (_getSplunkWebUri(), appName)
def addUploadAssets(appName): appPath = _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException(_("App '%s' does not exist") % appName) tempPath = make_splunkhome_path(['var', 'run', 'splunk', 'apptemp']) # if does not exist then it means no assets exist for moving if not os.path.exists(tempPath): return dstPath = os.path.join(appPath, 'appserver', 'static') bundle_paths.maybe_makedirs(dstPath) comm.mergeDirs(tempPath, dstPath) # clean up bundle_paths.safe_remove(tempPath)
def addUploadAssets(appName): appPath = _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException( _("App '%s' does not exist") % appName) tempPath = make_splunkhome_path(['var', 'run', 'splunk', 'apptemp']) # if does not exist then it means no assets exist for moving if not os.path.exists(tempPath): return dstPath = os.path.join(appPath, 'appserver', 'static') bundle_paths.maybe_makedirs(dstPath) comm.mergeDirs(tempPath, dstPath) # clean up bundle_paths.safe_remove(tempPath)
def _getPackageDir(): if bundle_paths.maybe_makedirs(PACKAGE_PATH): return PACKAGE_PATH return None
def _getPackageDir(): if bundle_paths.maybe_makedirs(PACKAGE_PATH): return PACKAGE_PATH return None