Esempio n. 1
0
def install_files(self, app, settings, config):
    '''install files will add files (or directories) to a destination.
       If none specified, they are placed in the app base

       Parameters
       ==========
       app should be the name of the app, for lookup in config['apps']
       settings: the output of _init_app(), a dictionary of environment vars
       config: should be the config for the app obtained with self.app(app)

    '''
    if "appfiles" in config:
        files = config['appfiles']
        bot.info('+ ' + 'appfiles '.ljust(5) + app)

        for pair in files:
        
            # Step 1: determine source and destination
            src, dest = get_parts(pair, default=settings['approot'])

            # Step 2: copy source to destination
            cmd = ['cp']

            if os.path.isdir(src):
                cmd.append('-R')
            elif os.path.exists(src):
                cmd = cmd + [src, dest]
                result = self._run_command(cmd)
            else:    
                bot.warning('%s does not exist, skipping.' %src)
Esempio n. 2
0
def add_env(self, key, value):
    '''add a key/value pair to the environment. Should begin with SCIF
       to maintain proper namespace

    Parameters
    ==========
    key: the environment variable name. For SCIF, slashes should be 
         removed and replaced with underscore.
    value: the value to set for the environment variable

    '''    
    if not hasattr(self,'environment'):
        self.environment = dict()

    if not key.startswith('SCIF'):
        msg = 'Environment variable outside SCIF namespace not recommended.'
        bot.warning(msg)

    # If the variable already exists, status is "update"
    action = 'new'
    if key in self.environment:
        action = 'update'

    self.environment[key] = value
    bot.debug('[environment:%s][%s=%s]' %(action, key, value))
Esempio n. 3
0
def main(args,parser,subparser):

    from scif.main import ScifRecipe
    cmd = args.cmd

    if len(cmd) < 2:
        bot.warning('You must supply an appname and command to execute.')
        bot.custom(prefix="Example: ", message="scif exec app echo $SCIF_APPNAME")
        sys.exit(1)

    app = cmd.pop(0)
    client = ScifRecipe(quiet=True, writable=args.writable)
    client.execute(app, cmd)
Esempio n. 4
0
def deactivate(self, app):
    """if an app is valid, change the state so the app is no longer active.
       This is currently equivalent to calling reset, but only doing so if the
       app is defined for the SCIF.

    Parameters
    ==========
    app: the name of the app to deactivate
    """

    if app in self.apps():
        self.reset()

    else:
        bot.warning("%s is not an installed SCIF app" % app)
Esempio n. 5
0
def activate(self, app, cmd=None, args=None):
    """if an app is valid, get it's environment to make it active.
       Update the entrypoint to be relevant to the app runscript.
    
        Parameters
        ==========
        app: the name of the app to activate
        cmd: if defined, the entry point (command) to run. Otherwise uses apprun
        args: additional commands for the apprun

    """
    if app is None:
        bot.warning("No app selected, will run default %s" % self._entry_point)
        self.reset()

    elif app in self.apps():
        config = self.get_appenv(app)

        # Make app active
        self._active = app

        # Make sure bin is added to path, and lib to ld_library_path
        self.append_path("PATH", config["SCIF_APPBIN"])
        self.append_path("LD_LIBRARY_PATH", config["SCIF_APPLIB"])

        # Set the runscript, first to cmd provided (exec) then runscript
        if cmd != None:
            self._entry_point = parse_entrypoint(cmd)
            if args is not None:
                self._entry_point += parse_entrypoint(args)
        else:
            # Set the default entrypoint
            self._set_entrypoint(app, "SCIF_APPRUN", args)

        # Update the environment for active app (updates ScifRecipe object)
        appenv = self.get_appenv(app, isolated=False, update=True)

        self.load_env(app)  # load environment variables from app itself
        self.export_env()  # export all variables from client.environment

        # Only set entryfolder if user didn't set to something else
        if not SCIF_ENTRYFOLDER:
            self._entry_folder = appenv["SCIF_APPROOT"]

    else:
        bot.warning("%s is not an installed SCIF app" % app)
Esempio n. 6
0
def main(args, parser, subparser):

    from scif.main import ScifRecipe
    cmd = args.cmd

    if len(cmd) == 0:
        bot.warning('You must supply an appname to run.')
        bot.custom(prefix="Example: ", message="scif run <app>")
        sys.exit(1)

    app = cmd.pop(0)

    # Remaining arguments indicate options/args to pass on
    if len(cmd) == 0:
        cmd = None

    client = ScifRecipe(quiet=True, writable=args.writable)
    client.run(app, args=cmd)
Esempio n. 7
0
File: apps.py Progetto: satra/scif
def activate(self, app, cmd=None):
    '''if an app is valid, get it's environment to make it active.
       Update the entrypoint to be relevant to the app runscript.
    
    Parameters
    ==========
    app: the name of the app to activate
    cmd: if defined, the entry point (command) to run. Otherwise uses apprun
    '''
    if app is None:
        bot.warning('No app selected, will run default %s' %self._entry_point)    
        self.reset()

    elif app in self.apps():
        config = self.get_appenv(app)

        # Make app active
        self._active = app

        # Make sure bin is added to path, and lib to ld_library_path
        self.append_path('PATH', config['SCIF_APPBIN'])
        self.append_path('LD_LIBRARY_PATH', config['SCIF_APPLIB'])

        # Set the runscript, first to cmd provided (exec) then runscript
        if cmd is not None:
            self._entry_point = parse_entrypoint(cmd)
        
        elif 'SCIF_APPRUN' in config:
            if os.path.exists(config['SCIF_APPRUN']):
                self._entry_point = [SCIF_SHELL, config['SCIF_APPRUN']]
 
        # Update the environment for active app (updates ScifRecipe object)
        appenv = self.get_appenv(app, isolated=False, update=True)

        self.load_env(app)  # load environment variables from app itself
        self.export_env()   # export all variables from client.environment

        # Only set entryfolder if user didn't set to something else
        if not SCIF_ENTRYFOLDER:
            self._entry_folder = appenv['SCIF_APPROOT']

    else:        
        bot.warning('%s is not an installed SCIF app' %app)
Esempio n. 8
0
def install_apps(self, apps=None):
    '''install one or more apps to the base. If app is defined, only
       install app specified. Otherwise, install all found in config.
    '''
    if apps in [None, '']:
        apps = self.apps()

    if not isinstance(apps, list):
        apps = [apps]

    if len(apps) == 0:
        bot.warning('No apps to install. Load a recipe or base with .load()')

    for app in apps:

        # We must have the app defined in the config
        if app not in self._config['apps']:
            bot.error('Cannot find app %s in config.' %app)
            sys.exit(1)

        # Make directories
        settings = self._init_app(app)

        # Get the app configuration
        config = self.app(app)

        # Get the app environment and export for install
        self.get_appenv(app, isolated=False, update=True)
        self.export_env(ps1=False)

        # Handle environment, runscript, labels
        self._install_runscript(app, settings, config)
        self._install_environment(app, settings, config)
        self._install_help(app, settings, config)
        self._install_labels(app, settings, config)
        self._install_files(app, settings, config)
        self._install_commands(app, settings, config)
        self._install_recipe(app, settings, config)
        self._install_test(app, settings, config)

        # After we install, in case interactive, deactivate last app
        self.deactivate(app)
Esempio n. 9
0
    def load(self, path, app=None, quiet=False):
        """load a scif recipe into the object

            Parameters
            ==========
            path: the complete path to the config (recipe file) to load, or 
                  root path of filesystem (that from calling function defaults to
                  /scif)
            app:  if running with context of an active app, this will load the
                  active app environment for it as well.
        """
        # 1. path is a recipe
        if os.path.isfile(path):
            self._config = load_recipe(path)

        # 2. path is a base
        elif os.path.isdir(path):
            self._config = load_filesystem(path, quiet=quiet)

        else:
            bot.warning("%s is not detected as a recipe or base." % path)
            self._config = None

        self.update_env(app)