Example #1
0
    def test_write_read_files(self):
        '''test_write_read_files will test the functions write_file and read_file
        '''
        print("Testing utils.write_file...")
        from scif.utils import write_file
        tmpfile = tempfile.mkstemp()[1]
        os.remove(tmpfile)
        write_file(tmpfile,"hello!")
        self.assertTrue(os.path.exists(tmpfile))        

        print("Testing utils.read_file...")
        from scif.utils import read_file
        content = read_file(tmpfile)[0]
        self.assertEqual("hello!",content)

        from scif.utils import write_json
        print("Testing utils.write_json...")
        print("...Case 1: Providing bad json")
        bad_json = {"Wakkawakkawakka'}":[{True},"2",3]}
        tmpfile = tempfile.mkstemp()[1]
        os.remove(tmpfile)        
        with self.assertRaises(TypeError) as cm:
            write_json(bad_json,tmpfile)

        print("...Case 2: Providing good json")        
        good_json = {"Wakkawakkawakka":[True,"2",3]}
        tmpfile = tempfile.mkstemp()[1]
        os.remove(tmpfile)
        write_json(good_json,tmpfile)
        with open(tmpfile,'r') as filey:
            content = json.loads(filey.read())
        self.assertTrue(isinstance(content,dict))
        self.assertTrue("Wakkawakkawakka" in content)
Example #2
0
def install_script(self, section, app, settings, config):
    '''a general function used by install_runscript, install_help, and
       install_environment to write a script to a file from a config setting
       section

       Parameters
       ==========
       section: should be the name of the section in the config (e.g., apprun)
       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 section in config:
        content = '\n'.join(config[section])
        bot.info('+ ' + section + ' '.ljust(5) + app)
        write_file(settings[section], content)
Example #3
0
def install_recipe(self, app, settings, config):
    '''Write the initial recipe for the app to its metadata folder.

       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)

    '''
    recipe_file = settings['apprecipe']
    recipe = '' 

    for section_name, section_content in config.items():
        content = '\n'.join(section_content)
        header = '%' + section_name
        recipe += '%s %s\n%s\n' %(header, app, content)

    write_file(recipe_file, recipe)
    return recipe
Example #4
0
def install_script(self, section, app, settings, config, executable=False):
    '''a general function used by install_runscript, install_help, and
       install_environment to write a script to a file from a config setting
       section

       Parameters
       ==========
       section: should be the name of the section in the config (e.g., apprun)
       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)
       executable: if the file is written, make it executable (defaults False)

    '''
    if section in config:
        content = '\n'.join(config[section])
        bot.info('+ ' + section + ' '.ljust(5) + app)
        write_file(settings[section], content)

        # Should we make the script executable (checks for exists)
        if executable is True:
            make_executable(settings[section])