def _getGitVersions(): """ Use git to query the versions of the core deployment and all plugins. :returns: a dictionary with 'core' and each plugin, each with git version information if it can be found. """ gitCommands = collections.OrderedDict([ ('SHA', ['rev-parse', 'HEAD']), ('shortSHA', ['rev-parse', '--short', 'HEAD']), ('lastCommitTime', ['log', '--format="%ai"', '-n1', 'HEAD']), ('branch', ['rev-parse', '--abbrev-ref', 'HEAD']), ]) versions = {} paths = collections.OrderedDict() if hasattr(girder, '__file__'): paths['core'] = fix_path( os.path.dirname(os.path.dirname(girder.__file__))) for plugin in plugin_utilities.findAllPlugins(): paths[plugin] = fix_path( os.path.join(plugin_utilities.getPluginDir(), plugin)) for key in paths: if os.path.exists(paths[key]): for info, cmd in six.iteritems(gitCommands): value = subprocess.Popen(['git'] + cmd, shell=False, stdout=subprocess.PIPE, cwd=paths[key]).stdout.read() value = value.strip().decode('utf8', 'ignore').strip('"') if (info == 'SHA' and key != 'core' and value == versions.get('core', {}).get('SHA', '')): break versions.setdefault(key, {})[info] = value return versions
def _getGitVersions(): """ Use git to query the versions of the core deployment and all plugins. :returns: a dictionary with 'core' and each plugin, each with git version information if it can be found. """ gitCommands = collections.OrderedDict([ ('SHA', ['rev-parse', 'HEAD']), ('shortSHA', ['rev-parse', '--short', 'HEAD']), ('lastCommitTime', ['log', '--format="%ai"', '-n1', 'HEAD']), ('branch', ['rev-parse', '--abbrev-ref', 'HEAD']), ]) versions = {} paths = collections.OrderedDict() if hasattr(girder, '__file__'): paths['core'] = fix_path(os.path.dirname(os.path.dirname(girder.__file__))) for plugin in plugin_utilities.findAllPlugins(): paths[plugin] = fix_path(os.path.join(plugin_utilities.getPluginDir(), plugin)) for key in paths: if os.path.exists(paths[key]): for info, cmd in six.iteritems(gitCommands): value = subprocess.Popen( ['git'] + cmd, shell=False, stdout=subprocess.PIPE, cwd=paths[key]).stdout.read() value = value.strip().decode('utf8', 'ignore').strip('"') if (info == 'SHA' and key != 'core' and value == versions.get('core', {}).get('SHA', '')): break versions.setdefault(key, {})[info] = value return versions
def install_plugin(source=None, force=False): """ Install one or more plugins from the given source. If no source is given, it will install all plugins in the release package on Github. The source provided must be a directory or tarball containing one or more directories which will be installed as individual plugins. :param str src: source specification (filesystem or url) :param bool force: allow overwriting existing files :returns: a list of plugins that were installed :rtype: list """ if source is None: # pragma: no cover source = defaultSource + 'girder-plugins-' + version + '.tar.gz' found = [] tmp = tempfile.mkdtemp() try: handle_source(source, tmp) plugins = [] for pth in os.listdir(tmp): pth = os.path.join(tmp, pth) if os.path.isdir(pth): plugins.append(pth) for plugin in plugins: pluginName = os.path.split(plugin)[1] pluginTarget = os.path.join(getPluginDir(), pluginName) if os.path.exists(pluginTarget): if force: shutil.rmtree(pluginTarget) else: print( constants.TerminalColor.warning( 'A plugin already exists at %s, ' 'use "force" to overwrite.' % pluginTarget)) continue found.append(pluginName) shutil.copytree(plugin, pluginTarget) requirements = os.path.join(pluginTarget, 'requirements.txt') if os.path.exists(requirements): # pragma: no cover print( constants.TerminalColor.info( 'Attempting to install requirements for %s.\n' % pluginName)) if pip.main(['install', '-U', '-r', requirements]) != 0: print( constants.TerminalColor.error( 'Failed to install requirements for %s.' % pluginName)) finally: shutil.rmtree(tmp) return found
def __init__(self, templatePath=None): if not templatePath: templatePath = os.path.join(getPluginDir(), 'isic_archive', 'server', 'webroot.mako') super(Webroot, self).__init__(templatePath) self.vars = { 'apiRoot': '/api/v1', 'staticRoot': '/static', 'title': 'ISIC Archive' }
def __init__(self, templatePath=None): if not templatePath: templatePath = os.path.join(getPluginDir(), 'review', 'server', 'webroot.mako') super(Webroot, self).__init__(templatePath) self.vars = { 'apiRoot': '/api/v1', 'staticRoot': '/static', 'title': 'Technical Journal Review' }
def __init__(self, templatePath=None): if not templatePath: templatePath = os.path.join(getPluginDir(), 'slicer_extension_manager', 'server', 'webroot.mako') super(Webroot, self).__init__(templatePath) self.vars = { 'apiRoot': '/api/v1', 'staticRoot': '/static', 'title': 'Slicer extension manager' }
def install_plugin(source=None, force=False): """ Install one or more plugins from the given source. If no source is given, it will install all plugins in the release package on Github. The source provided must be a directory or tarball containing one or more directories which will be installed as individual plugins. :param str src: source specification (filesystem or url) :param bool force: allow overwriting existing files :returns: a list of plugins that were installed :rtype: list """ if source is None: # pragma: no cover source = defaultSource + 'girder-plugins-' + version + '.tar.gz' found = [] tmp = tempfile.mkdtemp() try: handle_source(source, tmp) plugins = [] for pth in os.listdir(tmp): pth = os.path.join(tmp, pth) if os.path.isdir(pth): plugins.append(pth) for plugin in plugins: pluginName = os.path.split(plugin)[1] pluginTarget = os.path.join(getPluginDir(), pluginName) if os.path.exists(pluginTarget): if force: shutil.rmtree(pluginTarget) else: print constants.TerminalColor.warning( 'A plugin already exists at %s, ' 'use "force" to overwrite.' % pluginTarget ) continue found.append(pluginName) shutil.copytree(plugin, pluginTarget) requirements = os.path.join(pluginTarget, 'requirements.txt') if os.path.exists(requirements): # pragma: no cover print constants.TerminalColor.info( 'Attempting to install requirements for %s.\n' % pluginName ) if pip.main(['install', '-U', '-r', requirements]) != 0: print constants.TerminalColor.error( 'Failed to install requirements for %s.' % pluginName ) finally: shutil.rmtree(tmp) return found
def install_plugin(opts): """ Install a list of plugins into a packaged Girder environment. This first copies the plugin dir recursively into the Girder primary plugin directory, then installs the plugin using pip (if setup.py exists) or installs dependencies from a requirements.txt file (otherwise, and if that file exists). After all plugins have finished installing, we run `npm install` to build all of the web client code. :param opts: Options controlling the behavior of this function. Must be an object with a "plugin" attribute containing a list of plugin paths, and a boolean "force" attribute representing the force overwrite flag. """ for plugin in opts.plugin: pluginPath = fix_path(plugin) name = os.path.basename(pluginPath) print(constants.TerminalColor.info('Installing %s...' % name)) if not os.path.isdir(pluginPath): raise Exception('Invalid plugin directory: %s' % pluginPath) if not opts.skip_requirements: _install_plugin_reqs(pluginPath, name, opts.development) targetPath = os.path.join(plugin_utilities.getPluginDir(), name) if (os.path.isdir(targetPath) and os.path.samefile(pluginPath, targetPath) and not opts.symlink ^ os.path.islink(targetPath)): # If source and dest are the same, we are done for this plugin. # Note: ^ is a logical xor - not xor means only continue if # symlink and islink() are either both false, or both true continue if os.path.exists(targetPath): if opts.force: print( constants.TerminalColor.warning( 'Removing existing plugin at %s.' % targetPath)) if os.path.islink(targetPath): os.unlink(targetPath) else: shutil.rmtree(targetPath) else: raise Exception( 'Plugin already exists at %s, use "-f" to overwrite the existing directory.' % targetPath) if opts.symlink: os.symlink(pluginPath, targetPath) else: shutil.copytree(pluginPath, targetPath)
def install_plugin(opts): """ Install a list of plugins into a packaged Girder environment. This first copies the plugin dir recursively into the Girder primary plugin directory, then installs the plugin using pip (if setup.py exists) or installs dependencies from a requirements.txt file (otherwise, and if that file exists). After all plugins have finished installing, we run `npm install` to build all of the web client code. :param opts: Options controlling the behavior of this function. Must be an object with a "plugin" attribute containing a list of plugin paths, and a boolean "force" attribute representing the force overwrite flag. """ for plugin in opts.plugin: pluginPath = fix_path(plugin) name = os.path.basename(pluginPath) print(constants.TerminalColor.info('Installing %s...' % name)) if not os.path.isdir(pluginPath): raise Exception('Invalid plugin directory: %s' % pluginPath) if not opts.skip_requirements: _install_plugin_reqs(pluginPath, name, opts.development) targetPath = os.path.join(plugin_utilities.getPluginDir(), name) if (os.path.isdir(targetPath) and os.path.samefile(pluginPath, targetPath) and not opts.symlink ^ os.path.islink(targetPath)): # If source and dest are the same, we are done for this plugin. # Note: ^ is a logical xor - not xor means only continue if # symlink and islink() are either both false, or both true continue if os.path.exists(targetPath): if opts.force: print(constants.TerminalColor.warning( 'Removing existing plugin at %s.' % targetPath)) if os.path.islink(targetPath): os.unlink(targetPath) else: shutil.rmtree(targetPath) else: raise Exception( 'Plugin already exists at %s, use "-f" to overwrite the existing directory.' % targetPath) if opts.symlink: os.symlink(pluginPath, targetPath) else: shutil.copytree(pluginPath, targetPath)
def testGetPluginDir(self): # Test that plugin_install_path option takes first precedence conf = config.getConfig() conf['plugins']['plugin_install_path'] = 'use_this_plugin_dir' self.assertEqual(plugin_utilities.getPluginDir(), 'use_this_plugin_dir') try: shutil.rmtree('use_this_plugin_dir') except OSError: pass del conf['plugins']['plugin_install_path']
def install_plugin(opts): """ Install a list of plugins into a packaged Girder environment. This first copies the plugin dir recursively into the Girder primary plugin directory, then installs all of its pip requirements from its requirements.txt file if one exists. After all plugins have finished installing, we run `npm install` to build all of the web client code. :param opts: Options controlling the behavior of this function. Must be an object with a "plugin" attribute containing a list of plugin paths, and a boolean "force" attribute representing the force overwrite flag. """ for plugin in opts.plugin: pluginPath = fix_path(plugin) name = os.path.basename(pluginPath) print(constants.TerminalColor.info('Installing %s...' % name)) if not os.path.isdir(pluginPath): raise Exception('Invalid plugin directory: %s' % pluginPath) requirements = [os.path.join(pluginPath, 'requirements.txt')] if opts.development: requirements.extend([os.path.join(pluginPath, 'requirements-dev.txt')]) for reqs in requirements: if os.path.isfile(reqs): print(constants.TerminalColor.info( 'Installing pip requirements for %s from %s.' % (name, reqs))) if pip.main(['install', '-r', reqs]) != 0: raise Exception( 'Failed to install pip requirements at %s.' % reqs) targetPath = os.path.join(getPluginDir(), name) if (os.path.isdir(targetPath) and os.path.samefile(pluginPath, targetPath) and not opts.symlink ^ os.path.islink(targetPath)): # If source and dest are the same, we are done for this plugin. # Note: ^ is a logical xor - not xor means only continue if # symlink and islink() are either both false, or both true continue if os.path.exists(targetPath): if opts.force: print(constants.TerminalColor.warning( 'Removing existing plugin at %s.' % targetPath)) if os.path.islink(targetPath): os.unlink(targetPath) else: shutil.rmtree(targetPath) else: raise Exception('Plugin already exists at %s, use "-f" to ' 'overwrite the existing directory.' % ( targetPath, )) if opts.symlink: os.symlink(pluginPath, targetPath) else: shutil.copytree(pluginPath, targetPath) runNpmInstall(dev=opts.development, npm=opts.npm)
def print_plugin_path(parser): print(getPluginDir())
def print_plugin_path(parser): print(plugin_utilities.getPluginDir())