Example #1
0
 def write_file(self,
                filename=default_mpfile_path.replace('.txt', '_out.txt'),
                **kwargs):
     """Writes MPFile to a file. The supported kwargs are the same as those
     for the MPFile.get_string method and are passed through directly."""
     with codecs.open(filename, encoding='utf-8', mode='w') as f:
         file_str = self.get_string(**kwargs) + '\n'
         f.write(file_str)
Example #2
0
def load():
    mpfile = session.get('mpfile')
    if mpfile is None:
        return render_template('home.html',
                               alert='Choose an MPFile!',
                               session=session)
    input_mpfile_path = default_mpfile_path.replace('.txt', '_in.txt')
    with codecs.open(input_mpfile_path, encoding='utf-8', mode='w') as f:
        f.write(mpfile)
    return render_template('home.html', session=session)
Example #3
0
def load():
    mpfile = session.get('mpfile')
    if mpfile is None:
        return render_template(
            'home.html', alert='Choose an MPFile!', session=session
        )
    input_mpfile_path = default_mpfile_path.replace('.txt', '_in.txt')
    with codecs.open(input_mpfile_path, encoding='utf-8', mode='w') as f:
        f.write(mpfile)
    return render_template('home.html', session=session)
Example #4
0
def reset_session():
    global session
    session.clear()
    session['projects'] = projects
    session['options'] = ["archieml"]
    session['contribute'] = {}
    stop_processes()
    start_processes()
    for suffix in ['_in.txt', '_out.txt']:
        filepath = default_mpfile_path.replace('.txt', suffix)
        if os.path.exists(filepath):
            os.remove(filepath)
Example #5
0
def reset_session():
    global session
    session.clear()
    session['projects'] = projects
    session['options'] = ["archieml"]
    session['contribute'] = {}
    stop_processes()
    start_processes()
    for suffix in ['_in.txt', '_out.txt']:
      filepath = default_mpfile_path.replace('.txt', suffix)
      if os.path.exists(filepath):
        os.remove(filepath)
Example #6
0
    def from_file(cls, filename_or_file=default_mpfile_path.replace('.txt', '_in.txt')):
        """Reads a MPFile from a file.

        Args:
            filename_or_file (str or file): name of file or file containing contribution data.

        Returns:
            MPFile object.
        """
        f = open(filename_or_file) \
            if isinstance(filename_or_file, six.string_types) \
            else filename_or_file
        return cls.from_string(f.read())
Example #7
0
    def from_file(cls,
                  filename_or_file=default_mpfile_path.replace(
                      '.txt', '_in.txt')):
        """Reads a MPFile from a file.

        Args:
            filename_or_file (str or file): name of file or file containing contribution data.

        Returns:
            MPFile object.
        """
        if isinstance(filename_or_file, six.string_types):
            lang, encoding = locale.getdefaultlocale()
            file_string = codecs.open(filename_or_file,
                                      encoding=encoding).read()
        else:
            file_string = filename_or_file.read()
        return cls.from_string(file_string)
Example #8
0
def reset_session():
    global session, processes
    current_app.config['JSON_SORT_KEYS'] = False
    current_app.secret_key = 'xxxrrr'
    session.clear()
    session['projects'] = projects
    session['options'] = ["archieml"]
    session['contribute'] = {}
    sbx_content = current_app.config.get('SANDBOX_CONTENT')
    if sbx_content is not None:
        session['sbx_content'] = sbx_content
    session['jupyter_url'] = current_app.config.get('JUPYTER_URL')
    if not current_app.config.get('START_JUPYTER') and 'NotebookProcess' in processes:
        processes.pop('NotebookProcess')
    if not current_app.config.get('START_MONGODB') and 'MongodProcess' in processes:
        processes.pop('MongodProcess')
    stop_processes()
    start_processes()
    for suffix in ['_in.txt', '_out.txt']:
      filepath = default_mpfile_path.replace('.txt', suffix)
      if os.path.exists(filepath):
        os.remove(filepath)
Example #9
0
def reset_session():
    global session, processes
    current_app.config['JSON_SORT_KEYS'] = False
    current_app.secret_key = 'xxxrrr'
    session.clear()
    session['projects'] = projects
    session['options'] = ["archieml"]
    session['contribute'] = {}
    sbx_content = current_app.config.get('SANDBOX_CONTENT')
    if sbx_content is not None:
        session['sbx_content'] = sbx_content
    session['jupyter_url'] = current_app.config.get('JUPYTER_URL')
    if not current_app.config.get(
            'START_JUPYTER') and 'NotebookProcess' in processes:
        processes.pop('NotebookProcess')
    if not current_app.config.get(
            'START_MONGODB') and 'MongodProcess' in processes:
        processes.pop('MongodProcess')
    stop_processes()
    start_processes()
    for suffix in ['_in.txt', '_out.txt']:
        filepath = default_mpfile_path.replace('.txt', suffix)
        if os.path.exists(filepath):
            os.remove(filepath)
Example #10
0
def read_mpfile_to_view():
    output_mpfile_path = default_mpfile_path.replace('.txt', '_out.txt')
    if os.path.exists(output_mpfile_path):
        return codecs.open(output_mpfile_path, encoding='utf-8').read()
    else:
        return session.get('mpfile')
Example #11
0
def read_mpfile_to_view():
    output_mpfile_path = default_mpfile_path.replace('.txt', '_out.txt')
    if os.path.exists(output_mpfile_path):
        return codecs.open(output_mpfile_path, encoding='utf-8').read()
    else:
        return session.get('mpfile')