예제 #1
0
    def __init__(self, options):
        self.conf = Config()
        self.conf.load(options.config_file)
        self.log_file = self.conf.get_option('hamster.log_file')
        self.ids = []
        if path.exists(self.log_file):
            f = file(self.log_file, 'r')
            self.ids = f.readlines()
        else:
            f = file(self.log_file, 'w')
            f.close()

        self.tasks = get_all_tasks(self.conf)

        for id in self.tasks:
            str_id = ('%d\n' % id)
            if str_id in self.ids:
                self.tasks[id].remote_sync = True
예제 #2
0
파일: app.py 프로젝트: ejimenez/Cobaya
    def __init__(self, options):
        self.conf = Config()
        self.conf.load(options.config_file)
        self.log_file = self.conf.get_option('hamster.log_file')
        self.ids = []
        if path.exists(self.log_file):
            f = file(self.log_file, 'r')
            self.ids = f.readlines()
        else:
            f = file(self.log_file, 'w')
            f.close()

        self.tasks = get_all_tasks(self.conf)

        for id in self.tasks:
            str_id = ('%d\n' % id)
            if str_id in self.ids:
                self.tasks[id].remote_sync = True
예제 #3
0
파일: app.py 프로젝트: ejimenez/Cobaya
class CobayaApp(object):

    def __init__(self, options):
        self.conf = Config()
        self.conf.load(options.config_file)
        self.log_file = self.conf.get_option('hamster.log_file')
        self.ids = []
        if path.exists(self.log_file):
            f = file(self.log_file, 'r')
            self.ids = f.readlines()
        else:
            f = file(self.log_file, 'w')
            f.close()

        self.tasks = get_all_tasks(self.conf)

        for id in self.tasks:
            str_id = ('%d\n' % id)
            if str_id in self.ids:
                self.tasks[id].remote_sync = True

    def generate_unsynced_data(self):
        data = []
        for id in self.tasks:
            if self.tasks[id].remote_sync == False and \
               self.tasks[id].time != 0.0:  # not synced or not finished
                data = self.append_and_merge(data, id)
        return data

    def append_and_merge(self, data, id):
        d = self.tasks[id].to_dict()
        band = False
        for i in range(len(data)):
            if data[i]['date'] == d['date'] and \
                    data[i]['project'] == d['project'] and \
                    data[i]['ticket'] == d['ticket']:
                data[i]['time'] += d['time']
                if (d['description'] and not data[i]['description']) or \
                   (d['description'] and not d['description'] in data[i]['description']):
                    if data[i]['description']:
                        data[i]['description'] = '%s ||| %s' % (data[i]['description'], d['description'])
                    else:
                        data[i]['description'] = d['description']
                band = True
        if not band or not len(data):
            data.append(d)
        return data

    def perform_notification(self):
        unsynced_data = self.generate_unsynced_data()

        server = RemoteServer(self.conf)
        responses = server.send_tasks(unsynced_data)
        news_id = []
        synced_tasks = responses['accepted'] + responses['duplicated']
        for task in synced_tasks:
            id = task['task_id']
            news_id.append("%d\n" % id)
            self.tasks[id].remote_sync = True
        f = file(self.log_file, 'a')
        f.writelines(news_id)
        f.close()
예제 #4
0
class CobayaApp(object):
    def __init__(self, options):
        self.conf = Config()
        self.conf.load(options.config_file)
        self.log_file = self.conf.get_option('hamster.log_file')
        self.ids = []
        if path.exists(self.log_file):
            f = file(self.log_file, 'r')
            self.ids = f.readlines()
        else:
            f = file(self.log_file, 'w')
            f.close()

        self.tasks = get_all_tasks(self.conf)

        for id in self.tasks:
            str_id = ('%d\n' % id)
            if str_id in self.ids:
                self.tasks[id].remote_sync = True

    def generate_unsynced_data(self):
        data = []
        for id in self.tasks:
            if self.tasks[id].remote_sync == False and \
               self.tasks[id].time != 0.0:  # not synced or not finished
                data = self.append_and_merge(data, id)
        return data

    def append_and_merge(self, data, id):
        d = self.tasks[id].to_dict()
        band = False
        for i in range(len(data)):
            if data[i]['date'] == d['date'] and \
                    data[i]['project'] == d['project'] and \
                    data[i]['ticket'] == d['ticket']:
                data[i]['time'] += d['time']
                if (d['description'] and not data[i]['description']) or \
                   (d['description'] and not d['description'] in data[i]['description']):
                    if data[i]['description']:
                        data[i]['description'] = '%s ||| %s' % (
                            data[i]['description'], d['description'])
                    else:
                        data[i]['description'] = d['description']
                band = True
        if not band or not len(data):
            data.append(d)
        return data

    def perform_notification(self):
        unsynced_data = self.generate_unsynced_data()

        server = RemoteServer(self.conf)
        responses = server.send_tasks(unsynced_data)
        news_id = []
        synced_tasks = responses['accepted'] + responses['duplicated']
        for task in synced_tasks:
            id = task['task_id']
            news_id.append("%d\n" % id)
            self.tasks[id].remote_sync = True
        f = file(self.log_file, 'a')
        f.writelines(news_id)
        f.close()