<commit_before>import os
from ConfigParser import ConfigParser
from biokbase.auth import kb_config

def getKBaseCfg():
    cfg = ConfigParser()
    if os.path.exists(kb_config):
        try:
            cfg.read(kb_config)
        except Exception, e:
            print 'Error while reading INI file %s: %s' % (kb_config, e)
    if not cfg.has_section('workspace_deluxe'):
        cfg.add_section('workspace_deluxe')
        with open(kb_config, 'w') as configfile:
            cfg.write(configfile)
    return cfg

def user_workspace(newWs = None):
    if newWs is not None:
        currentWs = newWs
        if 'KB_RUNNING_IN_IRIS' not in os.environ:
            cfg = getKBaseCfg()
            try:
                userId = cfg.get('authentication','user_id')
            except:
                userId = 'public'
            cfg.set('workspace_deluxe', userId+'-current-workspace', currentWs)
            with open(kb_config, 'w') as configfile:
                cfg.write(configfile)
        #else:
        #  perl logic:
        #    my $ujs = Bio::KBase::userandjobstate::Client->new();
        #    $ujs->set_state("Workspace","current-workspace",$currentWs);
    else:
        if 'KB_RUNNING_IN_IRIS' not in os.environ:
            cfg = getKBaseCfg()
            try:
                userId = cfg.get('authentication','user_id')
            except:
                userId = 'public'
            try:
                currentWs = cfg.get('workspace_deluxe', userId+'-current-workspace')
            except:
                # for compatibility, look for the old style workspace config variable 
                try:
                    currentWs = cfg.get('workspace_deluxe', 'workspace')
                    cfg.set('workspace_deluxe',userId+'-current-workspace')
                    cfg.remove_option('workspace_deluxe','workspace')
                    with open(kb_config, 'w') as configfile:
                        cfg.write(configfile)
                except:
                    # optionally, we can try here to retrieve from the User and Job State service first before we abort
                    raise "Default workspace not set.  Run ws-workspace to set your default workspace"<commit_msg>forgot to specify exception class for an exception in ScriptHelpers.py<commit_after>import os
from ConfigParser import ConfigParser
from biokbase.auth import kb_config

def getKBaseCfg():
    cfg = ConfigParser()
    if os.path.exists(kb_config):
        try:
            cfg.read(kb_config)
        except Exception, e:
            print 'Error while reading INI file %s: %s' % (kb_config, e)
    if not cfg.has_section('workspace_deluxe'):
        cfg.add_section('workspace_deluxe')
        with open(kb_config, 'w') as configfile:
            cfg.write(configfile)
    return cfg

def user_workspace(newWs = None):
    if newWs is not None:
        currentWs = newWs
        if 'KB_RUNNING_IN_IRIS' not in os.environ:
            cfg = getKBaseCfg()
            try:
                userId = cfg.get('authentication','user_id')
            except:
                userId = 'public'
            cfg.set('workspace_deluxe', userId+'-current-workspace', currentWs)
            with open(kb_config, 'w') as configfile:
                cfg.write(configfile)
        #else:
        #  perl logic:
        #    my $ujs = Bio::KBase::userandjobstate::Client->new();
        #    $ujs->set_state("Workspace","current-workspace",$currentWs);
    else:
        if 'KB_RUNNING_IN_IRIS' not in os.environ:
            cfg = getKBaseCfg()
            try:
                userId = cfg.get('authentication','user_id')
            except:
                userId = 'public'
            try:
                currentWs = cfg.get('workspace_deluxe', userId+'-current-workspace')
            except:
                # for compatibility, look for the old style workspace config variable 
                try:
                    currentWs = cfg.get('workspace_deluxe', 'workspace')
                    cfg.set('workspace_deluxe',userId+'-current-workspace')
                    cfg.remove_option('workspace_deluxe','workspace')
                    with open(kb_config, 'w') as configfile:
                        cfg.write(configfile)
                except:
                    # optionally, we can try here to retrieve from the User and Job State service first before we abort
                    raise Exception("Default workspace not set.  Run ws-workspace to set your default workspace")
{'fraction_non_alphanumeric': 0.09620535714285715, 'fraction_numerical': 0.0, 'mean_word_length': 1.9003236245954693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4878104', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1227, 'n_words': 316}