Exemple #1
0
def artifacts():
    artifacts = []
    for (dirpath, dirnames,
         filenames) in os.walk(session.get('upload_folder')):
        valid_filenames = [f for f in filenames if is_valid_filename(f)]
        for filename in valid_filenames:
            modified_ts = os.path.getmtime(os.path.join(dirpath, filename))
            modified = datetime.fromtimestamp(modified_ts).strftime(
                '%Y-%m-%d %H:%M:%S')
            artifacts.append({'filename': filename, 'modified': modified})
        break
    return render_template('artifacts.html', artifacts=artifacts)
Exemple #2
0
def artifacts_save():
    file = request.files['file']
    if is_valid_filename(file.filename):
        if is_valid_mimetype(file.mimetype):
            path = os.path.join(session.get('upload_folder'), file.filename)
            if not os.path.isfile(path):
                try:
                    file.save(path)
                except IOError:
                    flash('Unable to save the artifact.')
            else:
                flash('An artifact with that name already exists.')
        else:
            flash('Invalid file type. Only {} types allowed.'.format(', '.join(
                current_app.config['ALLOWED_MIMETYPES'])))
    else:
        flash('Invalid file extension. Only {} extensions allowed.'.format(
            ', '.join(current_app.config['ALLOWED_EXTENSIONS'])))
    return redirect(url_for('core.artifacts'))