Ejemplo n.º 1
0
    def set(self, action_type, cmd, start, end):
        self.task = DMTask()
        self.r = None
        self.val = {"action_type": action_type, "start": start, "end": end}
        if cmd == "get_repos":
            self.val["name"] = "get_repos"
            self.task.init("github", self.val)
            self.r = GithubRepo(self.task)
        elif cmd == "get_followers":
            self.val["name"] = "get_followers"
            self.task.init("github", self.val)
            self.r = GithubFollowers(self.task)
        elif cmd == "get_events":
            self.val["name"] = "get_events"
            self.task.init("github", self.val)
            self.r = GithubEvent(self.task)


# TODO: do not support now
        elif cmd == "get_users":
            self.val["name"] = "get_users"
            self.task.init("github", self.val)
            self.r = GithubUser(self.task)
        elif cmd == "get_repositories":
            self.val["name"] = "get_repositories"
            self.task.init("github", self.val)
            self.r = GithubRepositories(self.task)
        elif cmd == "get_contributors":
            self.val["name"] = "get_contributors"
            self.task.init("github", self.val)
            self.r = GithubContributors(self.task)
        elif cmd == "get_commit":
            self.val["name"] = "get_commit"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        elif cmd == "get_commit_p1":
            self.val["name"] = "get_commit_p1"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        else:
            print "Failed to init the task"
            return 0
        return 1
Ejemplo n.º 2
0
 def set(self, action_type, cmd, start, end):
     self.task = DMTask()
     self.r = None
     self.val = {"action_type": action_type, "start": start, "end": end}
     if cmd == "get_repos":
         self.val["name"] = "get_repos"
         self.task.init("github", self.val)
         self.r = GithubRepo(self.task)
     elif cmd == "get_followers":
         self.val["name"] = "get_followers"
         self.task.init("github", self.val)
         self.r = GithubFollowers(self.task)
     elif cmd == "get_events":
         self.val["name"] = "get_events"
         self.task.init("github", self.val)
         self.r = GithubEvent(self.task)
     # TODO: do not support now
     elif cmd == "get_users":
         self.val["name"] = "get_users"
         self.task.init("github", self.val)
         self.r = GithubUser(self.task)
     elif cmd == "get_repositories":
         self.val["name"] = "get_repositories"
         self.task.init("github", self.val)
         self.r = GithubRepositories(self.task)
     elif cmd == "get_contributors":
         self.val["name"] = "get_contributors"
         self.task.init("github", self.val)
         self.r = GithubContributors(self.task)
     elif cmd == "get_commit":
         self.val["name"] = "get_commit"
         self.task.init("github", self.val)
         self.r = GithubCommit(self.task)
     elif cmd == "get_commit_p1":
         self.val["name"] = "get_commit_p1"
         self.task.init("github", self.val)
         self.r = GithubCommit(self.task)
     else:
         print "Failed to init the task"
         return 0
     return 1
Ejemplo n.º 3
0
class myThread(threading.Thread):
    def __init__(self, action_type, cmd, start, end, endless):
        threading.Thread.__init__(self)
        self.endless = endless
        self.set(action_type, cmd, start, end)

    def set(self, action_type, cmd, start, end):
        self.task = DMTask()
        self.r = None
        self.val = {"action_type": action_type, "start": start, "end": end}
        if cmd == "get_repos":
            self.val["name"] = "get_repos"
            self.task.init("github", self.val)
            self.r = GithubRepo(self.task)
        elif cmd == "get_followers":
            self.val["name"] = "get_followers"
            self.task.init("github", self.val)
            self.r = GithubFollowers(self.task)
        elif cmd == "get_events":
            self.val["name"] = "get_events"
            self.task.init("github", self.val)
            self.r = GithubEvent(self.task)
        # TODO: do not support now
        elif cmd == "get_users":
            self.val["name"] = "get_users"
            self.task.init("github", self.val)
            self.r = GithubUser(self.task)
        elif cmd == "get_repositories":
            self.val["name"] = "get_repositories"
            self.task.init("github", self.val)
            self.r = GithubRepositories(self.task)
        elif cmd == "get_contributors":
            self.val["name"] = "get_contributors"
            self.task.init("github", self.val)
            self.r = GithubContributors(self.task)
        elif cmd == "get_commit":
            self.val["name"] = "get_commit"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        elif cmd == "get_commit_p1":
            self.val["name"] = "get_commit_p1"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        else:
            print "Failed to init the task"
            return 0
        return 1

    def run(self):
        print "Starting " + str(self.val)
        if self.r:
            #            self.r.runFix2Task()
            self.r.runTask()
        print "Exiting " + str(self.val)

        if self.endless == 1:
            while 1:
                query = {"col": "github", "num": 1, "query": {"status": "init"}}
                #                query = {"col": "github", "num": 1, "query": {"status": "fixed", "name": "get_contributors"}}
                threadLock.acquire()
                res = DMTask().getFreeTasks(query)
                threadLock.release()
                if res:
                    for item in res:
                        print item
                        if self.set(item["name"], item["start"], item["end"]) == 1:
                            #                            self.r.runFix2Task()
                            self.r.runTask()
                        else:
                            return
                        print "\n Start another task in the finished thread\n"
                        break
Ejemplo n.º 4
0
class myThread(threading.Thread):
    def __init__(self, action_type, cmd, start, end, endless):
        threading.Thread.__init__(self)
        self.endless = endless
        self.set(action_type, cmd, start, end)

    def set(self, action_type, cmd, start, end):
        self.task = DMTask()
        self.r = None
        self.val = {"action_type": action_type, "start": start, "end": end}
        if cmd == "get_repos":
            self.val["name"] = "get_repos"
            self.task.init("github", self.val)
            self.r = GithubRepo(self.task)
        elif cmd == "get_followers":
            self.val["name"] = "get_followers"
            self.task.init("github", self.val)
            self.r = GithubFollowers(self.task)
        elif cmd == "get_events":
            self.val["name"] = "get_events"
            self.task.init("github", self.val)
            self.r = GithubEvent(self.task)


# TODO: do not support now
        elif cmd == "get_users":
            self.val["name"] = "get_users"
            self.task.init("github", self.val)
            self.r = GithubUser(self.task)
        elif cmd == "get_repositories":
            self.val["name"] = "get_repositories"
            self.task.init("github", self.val)
            self.r = GithubRepositories(self.task)
        elif cmd == "get_contributors":
            self.val["name"] = "get_contributors"
            self.task.init("github", self.val)
            self.r = GithubContributors(self.task)
        elif cmd == "get_commit":
            self.val["name"] = "get_commit"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        elif cmd == "get_commit_p1":
            self.val["name"] = "get_commit_p1"
            self.task.init("github", self.val)
            self.r = GithubCommit(self.task)
        else:
            print "Failed to init the task"
            return 0
        return 1

    def run(self):
        print "Starting " + str(self.val)
        if self.r:
            #            self.r.runFix2Task()
            self.r.runTask()
        print "Exiting " + str(self.val)

        if self.endless == 1:
            while 1:
                query = {
                    "col": "github",
                    "num": 1,
                    "query": {
                        "status": "init"
                    }
                }
                #                query = {"col": "github", "num": 1, "query": {"status": "fixed", "name": "get_contributors"}}
                threadLock.acquire()
                res = DMTask().getFreeTasks(query)
                threadLock.release()
                if res:
                    for item in res:
                        print item
                        if self.set(item["name"], item["start"],
                                    item["end"]) == 1:
                            #                            self.r.runFix2Task()
                            self.r.runTask()
                        else:
                            return
                        print "\n Start another task in the finished thread\n"
                        break