<commit_before>import logging
import gitlab
from datetime import datetime
from pprint import pprint as pprint
import os
from app import app

log = app.logger
log.setLevel(logging.DEBUG)


PRIVATE_TOKEN = "<KEY>"
PROJECT = 15

git = gitlab.Gitlab('http://gitlab.clariah-sdh.eculture.labs.vu.nl', token=PRIVATE_TOKEN)


def list_projects():
    projects = list(git.getall(git.getprojects))

    return projects


def get_project_info():
    try:
        info = git.getproject(PROJECT)
        log.debug("Retrieved project info from Gitlab for project {}".format(PROJECT))
        return info
    except:
        log.error("Could not retrieve project info for project {}".format(PROJECT))


def get_file(file_path, content):
    file_info = get_file_info(file_path)
    # TODO: This should actually be the file object. Let's first see how that ties into the code in views.py
    return file_info['url']

def get_file_info(file_path):
    project_info = git.getproject(PROJECT)
    file_info = git.getfile(PROJECT, file_path, "master")

    # Add 'url' to file_info
    file_info['url'] = project_info["web_url"] + "/raw/" + file_info["ref"] + "/" + file_info["file_path"]


def add_file(file_path, content):
    success = git.updatefile(PROJECT,<commit_msg>Incomplete implementation of GitLab browser (to replace the file browser in the file client)<commit_after>import logging
import gitlab
from datetime import datetime
from pprint import pprint as pprint
import os
from app import app

log = app.logger
log.setLevel(logging.DEBUG)


PRIVATE_TOKEN = "<KEY>"
PROJECT = 15

git = gitlab.Gitlab('http://gitlab.clariah-sdh.eculture.labs.vu.nl', token=PRIVATE_TOKEN)


def list_projects():
    projects = list(git.getall(git.getprojects))

    return projects


def get_project_info():
    try:
        info = git.getproject(PROJECT)
        log.debug("Retrieved project info from Gitlab for project {}".format(PROJECT))
        return info
    except:
        log.error("Could not retrieve project info for project {}".format(PROJECT))


def browse(base_path, relative_path):
    # @base_path is necessary for legacy purposes (file browser)
    # TODO: This currently does not work as it should, as the way we have to compute
    # the parent path of the current path is unclear (we don't have that information)

    log.debug('Browsing {}'.format(relative_path))

    files = git.getrepositorytree(PROJECT, path=relative_path, ref_name='master')

    filelist = []
    for p in files:
        path = "{}/{}".format(relative_path, p['name'])
        if p['name'][-3:] == 'csv':
            filelist.append({'label': p['name'], 'uri': path, 'mimetype': 'text/csv', 'type': 'file'})
        elif p['type'] == 'tree':
            filelist.append({'label': p['name'], 'uri': path, 'mimetype': 'inode/directory', 'type': 'dir'})

    # TODO: This is where things break.
    if base_path is '':
        parent = None
    else:
        parent = {'label': '..', 'uri': parent_path, 'mimetype': 'inode/directory', 'type': 'dir'}

    return filelist, parent


def get_file(file_path, content):
    file_info = get_file_info(file_path)
    # TODO: This should actually be the file object. Let's first see how that ties into the code in views.py
    return file_info['url']

def get_file_info(file_path):
    project_info = git.getproject(PROJECT)
    file_info = git.getfile(PROJECT, file_path, "master")

    # Add 'url' to file_info
    file_info['url'] = project_info["web_url"] + "/raw/" + file_info["ref"] + "/" + file_info["file_path"]


def add_file(file_path, content):
    success = git.updatefile(PROJECT,
{'fraction_non_alphanumeric': 0.12638888888888888, 'fraction_numerical': 0.001388888888888889, 'mean_word_length': 3.7949400798934754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4096410', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1127, 'n_words': 328}