Esempio n. 1
0
 def add(cls, description, owner_id, is_public, gist_names=[],
         gist_contents=[], fork_from=None):
     now = datetime.now()
     if fork_from:
         name = cls.get(fork_from).name
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `created_at`, `fork_from`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, now, fork_from))
         store.commit()
         gist = cls.get(id)
         fork_from = cls.get(fork_from)
         fork_from.fork_repo(gist)
         gist_forked_signal.send(gist, gist_id=gist.id)
     else:
         name = cls._get_name(names=gist_names)
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `is_public`, `created_at`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, is_public, now))
         store.commit()
         gist = cls.get(id)
         gist.create_repo()
         gist._commit_all_files(gist_names, gist_contents, create=True)
         gist_created_signal.send(gist, gist_id=gist.id)
     return gist
Esempio n. 2
0
 def add(cls, name, followed_user_name):
     time = datetime.now()
     store.execute(
         'insert into follow_relationship '
         '(user_name, followed_user_name, time) '
         'values (%s, %s, %s)', (name, followed_user_name, time))
     store.commit()
Esempio n. 3
0
 def revoke(self):
     now = datetime.now()
     store.execute(
         "update api_token set expire_time=%s, refresh_expire_time=%s "
         "where id=%s", (now, now, self.id))
     store.commit()
     self.expire_time = self.refresh_expire_time = now
Esempio n. 4
0
 def discover(cls, name, sort='created', direction='desc', start=0,
              limit=5):
     assert sort in SORTS
     assert direction in DIRECTIONS
     sortby = "order by %s_at %s " % (sort, direction)
     sort = '%s_at' % sort
     reverse = direction == 'desc'
     if name == 'forked':
         rs = store.execute("select distinct(fork_from) from gists "
                            "where fork_from!=0 and is_public=1 " +
                            sortby + "limit %s, %s",
                            (start, limit))
         return [cls.get(r) for r, in rs]
     elif name == 'starred':
         rs = store.execute("select distinct(gist_id) from gist_stars "
                            "order by created_at " +
                            direction + " limit %s, %s",
                            (start, limit))
         gists = filter(None, [cls.get(r) for r, in rs])
         return sorted(gists, key=lambda g: getattr(g, sort),
                       reverse=reverse)
     else:
         rs = store.execute(
             "select id, name, description, owner_id, is_public, "
             "fork_from, created_at, updated_at from gists where "
             "is_public=1 " + sortby + "limit %s, %s",
             (start, limit))
         return [cls(*r) for r in rs]
Esempio n. 5
0
    def test_project_stat(self):
        store.execute("delete from codedouban_projects where project_id < 5")
        project_rs = get_all_project()
        assert len(project_rs) == 0
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 0

        project_name = "project"
        project = CodeDoubanProject.add(
            project_name, owner_id="test1", summary="test", product="fire")
        git_path = os.path.join(get_repo_root(), '%s.git' % project_name)
        ok_(os.path.exists(git_path))
        project_rs = get_all_project()
        assert len(project_rs) == 1
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 0

        project_fork = project.fork('project_test_fork', 'test_fork')
        project_rs = get_all_project()
        assert len(project_rs) == 2
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 1

        project.delete()
        project_fork.delete()
Esempio n. 6
0
    def test_project_stat(self):
        store.execute("delete from codedouban_projects where project_id < 5")
        project_rs = get_all_project()
        assert len(project_rs) == 0
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 0

        project_name = "project"
        project = CodeDoubanProject.add(project_name,
                                        owner_id="test1",
                                        summary="test",
                                        product="fire")
        git_path = os.path.join(get_repo_root(), '%s.git' % project_name)
        ok_(os.path.exists(git_path))
        project_rs = get_all_project()
        assert len(project_rs) == 1
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 0

        project_fork = project.fork('project_test_fork', 'test_fork')
        project_rs = get_all_project()
        assert len(project_rs) == 2
        project_fork_count = len(filter(lambda x: x[1] is not None,
                                        project_rs))
        assert project_fork_count == 1

        project.delete()
        project_fork.delete()
Esempio n. 7
0
 def add(cls,
         title,
         description,
         creator,
         number=None,
         team=None,
         project=None,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None):
     issue = Issue.add(title,
                       description,
                       creator,
                       assignee=assignee,
                       closer=closer,
                       type=cls.target_type,
                       target_id=project)
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             'insert into project_issues (project_id, issue_id, number) '
             'values (%s, %s, %s) ', (project, issue.id, number))
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'open'))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'closed'))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Esempio n. 8
0
 def update(self, title='', description=''):
     store.execute(
         "update codedouban_ticket set title=%s, description=%s "
         "where id=%s", (title, description, self.id))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % self.id, description)
Esempio n. 9
0
 def add(cls, name, followed_user_name):
     time = datetime.now()
     store.execute('insert into follow_relationship '
                   '(user_name, followed_user_name, time) '
                   'values (%s, %s, %s)',
                   (name, followed_user_name, time))
     store.commit()
Esempio n. 10
0
 def add(
     cls,
     title,
     description,
     creator,
     number=None,
     team=None,
     project=None,
     assignee=None,
     closer=None,
     created_at=None,
     updated_at=None,
     closed_at=None,
 ):
     issue = Issue.add(
         title, description, creator, assignee=assignee, closer=closer, type=cls.target_type, target_id=project
     )
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             "insert into project_issues (project_id, issue_id, number) " "values (%s, %s, %s) ",
             (project, issue.id, number),
         )
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "open"))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "closed"))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Esempio n. 11
0
 def discover(cls,
              name,
              sort='created',
              direction='desc',
              start=0,
              limit=5):
     assert sort in SORTS
     assert direction in DIRECTIONS
     sortby = "order by %s_at %s " % (sort, direction)
     sort = '%s_at' % sort
     reverse = direction == 'desc'
     if name == 'forked':
         rs = store.execute(
             "select distinct(fork_from) from gists "
             "where fork_from!=0 and is_public=1 " + sortby +
             "limit %s, %s", (start, limit))
         return [cls.get(r) for r, in rs]
     elif name == 'starred':
         rs = store.execute(
             "select distinct(gist_id) from gist_stars "
             "order by created_at " + direction + " limit %s, %s",
             (start, limit))
         gists = filter(None, [cls.get(r) for r, in rs])
         return sorted(gists,
                       key=lambda g: getattr(g, sort),
                       reverse=reverse)
     else:
         rs = store.execute(
             "select id, name, description, owner_id, is_public, "
             "fork_from, created_at, updated_at from gists where "
             "is_public=1 " + sortby + "limit %s, %s", (start, limit))
         return [cls(*r) for r in rs]
Esempio n. 12
0
 def update_product(self, product):
     store.execute("update codedouban_projects "
                   "set product=%s "
                   "where project_id=%s",
                   (product, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 13
0
 def update_summary(self, summary):
     store.execute("update codedouban_projects "
                   "set summary=%s "
                   "where project_id=%s",
                   (summary, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 14
0
 def update_intern_banned(self, banned):
     store.execute("update codedouban_projects "
                   "set intern_banned=%s "
                   "where project_id=%s",
                   (banned, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 15
0
 def update_product(self, product):
     store.execute("update codedouban_projects "
                   "set product=%s "
                   "where project_id=%s",
                   (product, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 16
0
 def update_summary(self, summary):
     store.execute("update codedouban_projects "
                   "set summary=%s "
                   "where project_id=%s",
                   (summary, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 17
0
def main():
    rs = store.execute("select id "
                       "from codedouban_ticket")
    for r in rs:
        id, = r
        ticket = Ticket.get(id)
        # update merge
        pullreq = PullRequest.get_by_ticket(ticket)
        author = pullreq.merge_by or pullreq.to_proj.owner_id
        time = pullreq.merge_time
        ticket_id = ticket.id
        id = 0
        if not get_node(author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time) and time:
            print id, author, time, ticket_id
            store.execute("insert into ticket_nodes "
                          "(author, type, type_id, ticket_id, created_at) "
                          "value (%s, %s, %s, %s, %s)",
                          (author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time))
            store.commit()
        # update close
        author = ticket.close_by or ticket.author
        time = ticket.closed
        ticket_id = ticket.id
        id = 0
        if not get_node(author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time) and time:
            print id, author, time, ticket_id
            store.execute("insert into ticket_nodes "
                          "(author, type, type_id, ticket_id, created_at) "
                          "value (%s, %s, %s, %s, %s)",
                          (author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time))
            store.commit()
    print "update %s close & merge pulls" % len(rs)
Esempio n. 18
0
 def update_intern_banned(self, banned):
     store.execute("update codedouban_projects "
                   "set intern_banned=%s "
                   "where project_id=%s",
                   (banned, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 19
0
 def add(cls,
         description,
         owner_id,
         is_public,
         gist_names=[],
         gist_contents=[],
         fork_from=None):
     now = datetime.now()
     if fork_from:
         name = cls.get(fork_from).name
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `created_at`, `fork_from`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, now, fork_from))
         store.commit()
         gist = cls.get(id)
         fork_from = cls.get(fork_from)
         fork_from.fork_repo(gist)
         gist_forked_signal.send(gist, gist_id=gist.id)
     else:
         name = cls._get_name(names=gist_names)
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `is_public`, `created_at`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, is_public, now))
         store.commit()
         gist = cls.get(id)
         gist.create_repo()
         gist._commit_all_files(gist_names, gist_contents, create=True)
         gist_created_signal.send(gist, gist_id=gist.id)
     return gist
Esempio n. 20
0
def get_item_count(name):
    if name == '':
        rs = store.execute("select count(1) from badge_item")
    else:
        rs = store.execute("select count(1) from badge_item where item_id=%s",
                           (name, ))
    data = rs and rs[0]
    return data
Esempio n. 21
0
 def update_can_push(self, can_push):
     push = 1 if can_push else 0
     store.execute("update codedouban_projects "
                   "set can_push=%s "
                   "where project_id=%s",
                   (push, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 22
0
 def add_committer(cls, proj_id, user_id):
     try:
         store.execute("insert into codedouban_committers "
                       "(project_id, user_id) values (%s, %s)",
                       (proj_id, user_id))
     except IntegrityError:
         return None
     store.commit()
Esempio n. 23
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id, ))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Esempio n. 24
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id,))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Esempio n. 25
0
 def update(self, title, description):
     store.execute("update issues "
                   "set title=%s, updated_at=null "
                   "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Esempio n. 26
0
 def update_can_push(self, can_push):
     push = 1 if can_push else 0
     store.execute("update codedouban_projects "
                   "set can_push=%s "
                   "where project_id=%s",
                   (push, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 27
0
def get_item_count(name):
    if name == '':
        rs = store.execute("select count(1) from badge_item")
    else:
        rs = store.execute(
            "select count(1) from badge_item where item_id=%s", (name,))
    data = rs and rs[0]
    return data
Esempio n. 28
0
 def add_committer(cls, proj_id, user_id):
     try:
         store.execute("insert into codedouban_committers "
                       "(project_id, user_id) values (%s, %s)",
                       (proj_id, user_id))
     except IntegrityError:
         return None
     store.commit()
Esempio n. 29
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)
Esempio n. 30
0
 def open(self):
     store.execute("update issues "
                   "set closer_id=null, closed_at=null "
                   "where id=%s", (self.issue_id,))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     self.closer_id = None
Esempio n. 31
0
 def transfer_to_top(self, user=None):
     new_user = user if user else self.owner_id
     sql = ("update codedouban_projects set project_name=%s, "
            "git_path=%s, trac_conf=%s, owner_id=%s "
            "where owner_id=%s and project_id=%s")
     store.execute(sql, (self.realname, self.realname, self.realname,
                         new_user, self.owner_id, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 32
0
 def transfer_to_top(self, user=None):
     new_user = user if user else self.owner_id
     sql = ("update codedouban_projects set project_name=%s, "
            "git_path=%s, trac_conf=%s, owner_id=%s "
            "where owner_id=%s and project_id=%s")
     store.execute(sql, (self.realname, self.realname, self.realname,
                         new_user, self.owner_id, self.id))
     store.commit()
     self.clear_mc(self.id)
Esempio n. 33
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id,))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Esempio n. 34
0
 def count_user_all(self, owner_id, is_self=False):
     if is_self:
         rs = store.execute(
             "select count(1) from gists where owner_id=%s", (owner_id,))
     else:
         rs = store.execute(
             "select count(1) from gists where owner_id=%s "
             "and is_public=1", (owner_id,))
     return rs[0][0]
Esempio n. 35
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id, ))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Esempio n. 36
0
 def update(self, description, gist_names=[], gist_contents=[],
            gist_oids=[]):
     name = self._get_name(gist_names)
     store.execute(
         "update gists set name=%s, description=%s, updated_at=%s where id=%s",  # noqa
         (name, description, datetime.now(), self.id))
     store.commit()
     self._commit_all_files(gist_names, gist_contents, gist_oids)
     gist_updated_signal.send(self, gist_id=self.id)
Esempio n. 37
0
 def count_user_all(self, owner_id, is_self=False):
     if is_self:
         rs = store.execute("select count(1) from gists where owner_id=%s",
                            (owner_id, ))
     else:
         rs = store.execute(
             "select count(1) from gists where owner_id=%s "
             "and is_public=1", (owner_id, ))
     return rs[0][0]
Esempio n. 38
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)
Esempio n. 39
0
 def update(self, title, description):
     store.execute(
         "update issues "
         "set title=%s, updated_at=null "
         "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Esempio n. 40
0
 def update(cls, summary, product, name, intern_banned=None):
     project_id = cls.get_id_by_name(name)
     if not project_id:
         return False
     store.execute(
         "update codedouban_projects set summary=%s, product=%s, "
         "intern_banned=%s where project_name=_latin1%s",
         (summary, product, intern_banned, name))
     store.commit()
     cls.clear_mc(project_id)
Esempio n. 41
0
 def open(self):
     store.execute(
         "update issues "
         "set closer_id=null, closed_at=null "
         "where id=%s", (self.issue_id, ))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     self.closer_id = None
Esempio n. 42
0
 def award(self, item_id, reason=None, kind=KIND_USER):
     params = (item_id, self.id, reason, kind, datetime.now())
     store.execute(
         "insert into badge_item(item_id, badge_id, reason, kind, date) "
         "values(%s, %s, %s, %s, %s)", params)
     store.commit()
     mc_key = MC_NEW_BADGE % (item_id, kind)
     badges = mc.get(mc_key) or []
     badges.append(str(self.id))
     mc.set(mc_key, badges)
Esempio n. 43
0
 def update(cls, summary, product, name, intern_banned=None):
     project_id = cls.get_id_by_name(name)
     if not project_id:
         return False
     store.execute(
         "update codedouban_projects set summary=%s, product=%s, "
         "intern_banned=%s where project_name=_latin1%s",
         (summary, product, intern_banned, name))
     store.commit()
     cls.clear_mc(project_id)
Esempio n. 44
0
 def add_related_project(self, repo_url):
     info = urlparse(repo_url)
     project_name = info.path.strip('/')
     from vilya.models.project import CodeDoubanProject
     prj = CodeDoubanProject.get_by_name(project_name)
     if prj not in self.related_projects:
         store.execute('insert into issue_related_projects '
                       '(issue_id, project_id) values(%s, %s)',
                       (self.issue_id, prj.id))
         store.commit()
Esempio n. 45
0
def main():
    rs = store.execute("select id, project_id, issue_id, number from project_issues")
    if rs:
        for r in rs:
            pi = ProjectIssue(*r)
            pi.update_rank_score()
    rs = store.execute("select id, team_id, issue_id, number from team_issues")
    if rs:
        for r in rs:
            ti = TeamIssue(*r)
            ti.update_rank_score()
Esempio n. 46
0
 def add_related_project(self, repo_url):
     info = urlparse(repo_url)
     project_name = info.path.strip('/')
     from vilya.models.project import CodeDoubanProject
     prj = CodeDoubanProject.get_by_name(project_name)
     if prj not in self.related_projects:
         store.execute(
             'insert into issue_related_projects '
             '(issue_id, project_id) values(%s, %s)',
             (self.issue_id, prj.id))
         store.commit()
Esempio n. 47
0
 def add(cls, user_id, target_id, kind, time=None):
     time = datetime.now()
     try:
         store.execute('insert into user_fav '
                       '(user_id, target_id, kind, time) '
                       'values (%s, %s, %s, %s)',
                       (user_id, target_id, kind, time))
         store.commit()
         return True
     except IntegrityError:
         return False
Esempio n. 48
0
 def add(cls, user_id, target_id, kind, time=None):
     time = datetime.now()
     try:
         store.execute(
             'insert into user_fav '
             '(user_id, target_id, kind, time) '
             'values (%s, %s, %s, %s)', (user_id, target_id, kind, time))
         store.commit()
         return True
     except IntegrityError:
         return False
Esempio n. 49
0
 def get_badge_items(cls, item_id=None, kind=KIND_USER):
     if item_id or kind != KIND_USER:
         params = (item_id, kind)
         rs = store.execute(
             "select badge_id, item_id, reason, date from badge_item "
             "where item_id=%s and kind=%s", params)
     else:
         rs = store.execute(
             "select badge_id, item_id, reason, date from badge_item "
             "order by date desc")
     return [BadgeItem(*item) for item in rs]
Esempio n. 50
0
def main():
    try:
        rs = store.execute("select project_id,owner_id from codedouban_projects")
        for r in rs:
            try:
                store.execute("insert into codedouban_watches (project_id, user_id) "
                              "values (%s, %s)",
                              (r[0], r[1]))
            except MySQLdb.IntegrityError, e:
                 print_exc()
        store.commit()
Esempio n. 51
0
 def update(self,
            description,
            gist_names=[],
            gist_contents=[],
            gist_oids=[]):
     name = self._get_name(gist_names)
     store.execute(
         "update gists set name=%s, description=%s, updated_at=%s where id=%s",  # noqa
         (name, description, datetime.now(), self.id))
     store.commit()
     self._commit_all_files(gist_names, gist_contents, gist_oids)
     gist_updated_signal.send(self, gist_id=self.id)
Esempio n. 52
0
 def test_gist_stat(self):
     store.execute("delete from gists where id < 20")
     gist_rs = get_all_gist()
     assert len(gist_rs) == 0
     g1 = self._add_gist()
     gist_rs = get_all_gist()
     assert len(gist_rs) == 1
     user_id = "testuser"
     g1.fork(user_id)
     gist_rs = get_all_gist()
     assert len(gist_rs) == 2
     assert len(filter(lambda x: x[1] != 0, gist_rs)) == 1
Esempio n. 53
0
    def add(cls, name, owner_id, summary='', product=None, fork_from=None,
            create_trac=False, intern_banned=None, mirror=None):
        # TODO: add project blacklist
        assert ' ' not in name, "Cannot create a project with spacey name"
        git_path = "%s.git" % name

        try:
            proj_id = store.execute(
                "insert into codedouban_projects "
                "(project_name, owner_id, summary, time, product, "
                "git_path, trac_conf, fork_from, intern_banned) values "
                "(%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                (name, owner_id, summary, datetime.now(),
                 product, git_path, name, fork_from, intern_banned))
        except IntegrityError:
            raise
            return None

        if fork_from is not None:
            origins = store.execute("select origin_project from "
                                    "codedouban_projects "
                                    "where project_id=%s", fork_from)
            origin_id, = origins[0]
        else:
            origin_id = proj_id
        store.execute("update codedouban_projects set origin_project=%s "
                      "where project_id=%s", (origin_id, proj_id))
        store.commit()
        cls.clear_mc(proj_id)

        project = cls.get(proj_id)
        # TODO: split create_repo, fork_repo, mirror_repo
        # create git repo
        if fork_from:
            orig_proj = cls.get(fork_from)
            orig_proj.fork_repo(project)
        elif mirror:
            from queues_handler import mirror_projects_add
            mirror_projects_add(mirror, git_path, proj_id)
        else:
            project.create_repo()

        if not mirror:
            project.update_hooks()

        cls._flush_project_ids_by_owner(owner_id)
        if fork_from:
            repo_fork_signal.send(
                project, project_id=proj_id, author=owner_id)
        else:
            repo_create_signal.send(
                project, project_id=proj_id, creator=owner_id)
        return project
Esempio n. 54
0
 def test_gist_stat(self):
     store.execute("delete from gists where id < 20")
     gist_rs = get_all_gist()
     assert len(gist_rs) == 0
     g1 = self._add_gist()
     gist_rs = get_all_gist()
     assert len(gist_rs) == 1
     user_id = "testuser"
     g1.fork(user_id)
     gist_rs = get_all_gist()
     assert len(gist_rs) == 2
     assert len(filter(lambda x: x[1] != 0, gist_rs)) == 1
Esempio n. 55
0
    def add(cls, name, owner_id, summary='', product=None, fork_from=None,
            create_trac=False, intern_banned=None, mirror=None):
        # TODO: add project blacklist
        assert ' ' not in name, "Cannot create a project with spacey name"
        git_path = "%s.git" % name

        try:
            proj_id = store.execute(
                "insert into codedouban_projects "
                "(project_name, owner_id, summary, time, product, "
                "git_path, trac_conf, fork_from, intern_banned) values "
                "(%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                (name, owner_id, summary, datetime.now(),
                 product, git_path, name, fork_from, intern_banned))
        except IntegrityError:
            raise
            return None

        if fork_from is not None:
            origins = store.execute("select origin_project from "
                                    "codedouban_projects "
                                    "where project_id=%s", fork_from)
            origin_id, = origins[0]
        else:
            origin_id = proj_id
        store.execute("update codedouban_projects set origin_project=%s "
                      "where project_id=%s", (origin_id, proj_id))
        store.commit()
        cls.clear_mc(proj_id)

        project = cls.get(proj_id)
        # TODO: split create_repo, fork_repo, mirror_repo
        # create git repo
        if fork_from:
            orig_proj = cls.get(fork_from)
            orig_proj.fork_repo(project)
        elif mirror:
            from queues_handler import mirror_projects_add
            mirror_projects_add(mirror, git_path, proj_id)
        else:
            project.create_repo()

        if not mirror:
            project.update_hooks()

        cls._flush_project_ids_by_owner(owner_id)
        if fork_from:
            repo_fork_signal.send(
                project, project_id=proj_id, author=owner_id)
        else:
            repo_create_signal.send(
                project, project_id=proj_id, creator=owner_id)
        return project
Esempio n. 56
0
 def incr(cls, proj_id, count=None):
     if count >= 0:
         sql = ("insert into pullreq_counter (project_id, counter) "
                "values (%s, LAST_INSERT_ID(%s)) on duplicate key "
                "update counter = LAST_INSERT_ID(%s)")
         id = store.execute(sql, (proj_id, count, count))
     else:
         sql = ("insert into pullreq_counter (project_id, counter) "
                "values (%s, LAST_INSERT_ID(%s)) on duplicate key "
                "update counter = LAST_INSERT_ID(counter + 1)")
         id = store.execute(sql, (proj_id, 1))
     store.commit()
     return id