예제 #1
0
  def project(self, a, **params):
    """List or delete projects"""
    db = cherrypy.thread_data.db
    data = None
    
    if a == "list":
      data = [p for p in db.projects.find().sort("name")]
      
    elif a == "delete":
      name = params["name"]
      db.projects.remove({"name": name})
      shutil.rmtree(REPOS_PATH + "/" + name)
      
    elif a == "update":
      name = params["name"]
      repo = GitTools.load_repo(name)
      if not repo:
        return output("NOT_EXIST")

      data = repo.git.pull()
      db.projects.update(
        {"name": name},
        {"$set": {"updated": time.time()}})
        
    elif a == "select":
      name = params["name"]
      db.projects.update(
        {"selected": True},
        {"$set": {"selected": False}})
      db.projects.update(
        {"name": name},
        {"$set": {"selected": True}})
    
    return output("OK", data)
예제 #2
0
 def browse_revision(self, name, sha, path):
   """List folder or read file of given revision."""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
   
   # Load revision
   try:
     tree = git.Commit(repo, sha.decode("hex")).tree
   except:
     return output("BAD_REVISION")
     
   # Load path
   node = Revisions.navigate_path(tree, path)
   if node is None:
     return output("BAD_PATH")
   
   # List content of folder
   if node.type == "tree":
     data = Revisions.list_folder(node)
   # Read syntax-highlighted file
   else:
     data = Revisions.show_file(node)
   
   return output(data=data)
예제 #3
0
 def summary(self, name, scope, section):
   """Brief stats about commits, developers, files, etc."""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
     
   since, until = GitTools.timerange(repo, scope)
   data = []
   
   if section == "commits":
     data = Summary.commits(repo, since, until)
   elif section == "developers":
     data = Summary.developers(repo, since, until)
   elif section == "files":
     data = Summary.files(repo, since, until)
   
   return output(data=data)
예제 #4
0
 def revisions(self, name):
   """Return last revisions of given project."""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
   
   revs = Revisions.list(repo)
   return output(data=revs)
예제 #5
0
 def developers(self, name, since, until):
   """List of developers with commits counts"""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
     
   since = int(since)
   until = int(until)
   data = Developers.list(repo, since, until)
 
   return output(data=data)
   
예제 #6
0
 def commits_info(self, name, since, until, **params):
   """Find commits in specified date range"""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
   
   commits = []  
   for c in repo.iter_commits(since=int(since), until=int(until)):
     commits.append({
       "sha": c.hexsha,
       "datetime": c.committed_date,
       "author": c.committer.name,
       "message": c.message
     })
   
   return output(data=commits)
예제 #7
0
 def commits(self, name, since, until, group):
   """Sum the daily commits in specified date range"""
   repo = GitTools.load_repo(name)
   if not repo:
     return output("NOT_EXIST")
   
   since = int(since)
   until = int(until)
   data = []
   
   if group == "daily":
     data = Commits.daily(repo, since, until)
   elif group == "weekday":
     data = Commits.weekday(repo, since, until)
   elif group == "hourly":
     data = Commits.hourly(repo, since, until)
   elif group == "monthly":
     data = Commits.monthly(repo, since, until)
     
   return output(data=data)
예제 #8
0
 def clone(self, **params):
   """Clone remote GIT repository"""
   db = cherrypy.thread_data.db
   
   # Get cloning status
   if "status" in params:
     key = cherrypy.session.get('sessid')
     return output("OK", db.clone_status.find_one({"_id": key}))
     
   # Clear cloning status
   elif "clear_status" in params:
     key = cherrypy.session.get('sessid')
     db.clone_status.remove({"_id": key})
     return output("OK")
     
   # Download repository
   else:
     url = params["url"]
     name = params["name"]
     key = cherrypy.session.originalid
     cherrypy.session['sessid'] = key
     
     st = GitTools.clone_repo(name, url, key)
     return output(st)