def get_repo(repo_id): """Return information about the repo. Meta: (immutable through this endpoint) * file tree * date repo was created * list of users by access level * access level of current auth context Settings: (mutable) * list of users by access level * remote repos with which to sync * privacy setting: (public or private) """ auth_context = get_auth_context() try: if not auth_context.can_read_repo(repo_id): return abort(http.UNAUTHORIZED) except KeyError: pass repo = Repository(os.path.join(current_app.config.get('git_root'), repo_id)) if not repo.is_valid_repo: abort(404) return jsonify({})
def add_repo(): """Create a new repository object Return {'url': '/<repo_id>/'} """ auth_context = get_auth_context() if not auth_context.can_create_repos: return abort(http.UNAUTHORIZED) # create a new auth context as the initial write key writer = KeyAuthContext() writer.save() meta = RepoMeta() meta.is_public = bool(request.form.get('is_public')) meta.access_admin.append(auth_context) meta.access_write.append(writer) meta.save() name = meta._id repo = Repository(os.path.join(current_app.config.get('git_root'), name)) repo.init() return jsonify({ 'url': url_for('.get_repo', repo_id=name), 'write_key': writer._id, })
def cloned_repo(self): return Repository( os.path.join( self.base_path, CLONED_REPO, ) )
def setUp(self): self.entry_path = os.getcwd() # base path containing all repos in test self.base_path = tempfile.mkdtemp() # path of the primary repo self.path = os.path.join( self.base_path, TEST_REPO, ) # instantiate the repo's Repository object self.repo = Repository(self.path) # initialize the repo self.repo.init() # change directory to the repo's root os.chdir(self.path)
from flask import Flask, jsonify, render_template, request import json import os import tempfile app = Flask(__name__) from git_subprocess import Repository repo_path = '/tmp/test/' # Set up a git repository for a storage backend repo = Repository(repo_path or tempfile.mkdtemp()) repo.init() # Homepage - just render the template @app.route('/') def index(): return render_template('index.html') # DELETE verb @app.route('/api/files/', methods=[ 'DELETE', ]) def delete_files(): # since multiple items could be deleted at once, iterate the list. for id in json.loads(request.form.get('ids', '[]')): repo._rm_file(id) repo.commit(
def get_repo(id): return Repository(os.path.join(current_app.config.get('git_root'), id))