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 packageApp(appName, needsMerging=True): appPath = mergeApp(appName) if needsMerging else _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException(_('The app "%s" cannot be found.') % appName) packageDir = _getPackageDir() tarFile = "%s.tar.gz" % appName tarPath = os.path.join(packageDir, tarFile) z = tarfile.open(tarPath, 'w:gz') # walk through files in directory and package them up def _tarWalker(tar, appPath, files, root=appPath): for file in files: file = os.path.join(appPath, file) archiveName = os.path.join(appName, file[len(os.path.commonprefix( (root, file) ))+1:]) # skip hidden unix files if os.sep + '.' in archiveName: continue tar.add(file, archiveName, False) os.path.walk(appPath , _tarWalker, z) z.close() # cleanup tmp dir if needsMerging: bundle_paths.safe_remove(appPath) splTarPath = tarPath.replace('tar.gz','spl') if os.path.exists(splTarPath): bundle_paths.safe_remove(splTarPath) os.rename(tarPath, splTarPath) url = '%s/static/app-packages/%s' % (_getSplunkdUri(), os.path.basename(splTarPath)) return (url, splTarPath)
def packageApp(appName, needsMerging=True): appPath = mergeApp(appName) if needsMerging else _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException( _('The app "%s" cannot be found.') % appName) packageDir = _getPackageDir() tarFile = "%s.tar.gz" % appName tarPath = os.path.join(packageDir, tarFile) z = tarfile.open(tarPath, 'w:gz') # walk through files in directory and package them up def _tarWalker(tar, appPath, files, root=appPath): for file in files: file = os.path.join(appPath, file) archiveName = os.path.join( appName, file[len(os.path.commonprefix((root, file))) + 1:]) # skip hidden unix files if os.sep + '.' in archiveName: continue # skip old default dirs if archiveName.startswith(os.path.join(appName, 'default.old.')): continue # set execution permission flag on extension-less files in bin directory if not os.path.isdir(file) and archiveName.startswith( os.path.join(appName, 'bin')): info = tarfile.TarInfo(name=archiveName.replace('\\', '/')) fobj = open(file, 'rb') info.size = os.fstat(fobj.fileno()).st_size info.mtime = os.path.getmtime(file) info.mode = 0755 tar.addfile(info, fileobj=fobj) fobj.close() else: tar.add(file, archiveName, False) os.path.walk(appPath, _tarWalker, z) z.close() # cleanup tmp dir if needsMerging: bundle_paths.safe_remove(appPath) splTarPath = tarPath.replace('tar.gz', 'spl') if os.path.exists(splTarPath): bundle_paths.safe_remove(splTarPath) os.rename(tarPath, splTarPath) url = '%s/static/app-packages/%s' % (_getSplunkdUri(), os.path.basename(splTarPath)) return (url, splTarPath)
def packageApp(appName, needsMerging=True): appPath = mergeApp(appName) if needsMerging else _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException(_('The app "%s" cannot be found.') % appName) packageDir = _getPackageDir() tarFile = "%s.tar.gz" % appName tarPath = os.path.join(packageDir, tarFile) z = tarfile.open(tarPath, 'w:gz') # walk through files in directory and package them up def _tarWalker(tar, appPath, files, root=appPath): for file in files: file = os.path.join(appPath, file) archiveName = os.path.join(appName, file[len(os.path.commonprefix( (root, file) ))+1:]) # skip hidden unix files if os.sep + '.' in archiveName: continue # skip old default dirs if archiveName.startswith(os.path.join(appName, 'default.old.')): continue # set execution permission flag on extension-less files in bin directory if not os.path.isdir(file) and archiveName.startswith(os.path.join(appName, 'bin')): info = tarfile.TarInfo(name=archiveName.replace('\\','/')) fobj = open(file,'rb') info.size = os.fstat(fobj.fileno()).st_size info.mtime = os.path.getmtime(file) info.mode = 0755 tar.addfile(info, fileobj=fobj) fobj.close() else: tar.add(file, archiveName, False) os.path.walk(appPath , _tarWalker, z) z.close() # cleanup tmp dir if needsMerging: bundle_paths.safe_remove(appPath) splTarPath = tarPath.replace('tar.gz','spl') if os.path.exists(splTarPath): bundle_paths.safe_remove(splTarPath) os.rename(tarPath, splTarPath) url = '%s/static/app-packages/%s' % (_getSplunkdUri(), os.path.basename(splTarPath)) return (url, splTarPath)
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 packageApp(appName, needsMerging=True): appPath = mergeApp(appName) if needsMerging else _getAppPath(appName, True) if not appPath: raise admin.ArgValidationException( _('The app "%s" cannot be found.') % appName) packageDir = _getPackageDir() tarFile = "%s.tar.gz" % appName tarPath = os.path.join(packageDir, tarFile) z = tarfile.open(tarPath, 'w:gz') # walk through files in directory and package them up def _tarWalker(tar, appPath, files, root=appPath): for file in files: file = os.path.join(appPath, file) archiveName = os.path.join( appName, file[len(os.path.commonprefix((root, file))) + 1:]) # skip hidden unix files if os.sep + '.' in archiveName: continue tar.add(file, archiveName, False) os.path.walk(appPath, _tarWalker, z) z.close() # cleanup tmp dir if needsMerging: bundle_paths.safe_remove(appPath) splTarPath = tarPath.replace('tar.gz', 'spl') if os.path.exists(splTarPath): bundle_paths.safe_remove(splTarPath) os.rename(tarPath, splTarPath) url = '%s/static/app-packages/%s' % (_getSplunkdUri(), os.path.basename(splTarPath)) return (url, splTarPath)