Exemplo n.º 1
0
    def post(self):
        try:
            json_data = request.get_json(force=True)
            issue = json_data['issue']
            start_time = json_data['start_time']
            end_time = json_data['end_time']
            username = json_data['username']
            # data = {}
            # data['info'] = {'issue': issue, 'start_time': start_time,
            # 'end_time': end_time, 'username': username}
            shared.set_issue_number(issue)
            tz = metadata.get_tz_info()
            start_time = metadata.convert_from_js(start_time, tz)
            end_time = metadata.convert_from_js(end_time, tz)
            start_time += ':00' + tz
            end_time += ':00' + tz
            issuenumber = shared.get_issue_number()

            note_dict = {}
            note_dict = {
                'user': shared.get_git_variables()['username'],
                'timestamp_start': start_time,
                'timestamp_end': end_time,
                'issue': issuenumber
            }
            gtc.store(target=[
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ],
                      content=note_dict)
            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Succes", newdata=newdata)
        except:
            print('CRASH!')
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Failed", data=newdata)
Exemplo n.º 2
0
 def post(self):
     json_data = request.get_json(force=True)
     sha1 = json_data['sha1']
     gtc.store(target=[
         shared.get_git_variables()['username'],
         datetime.now().year,
         datetime.now().month
     ],
               remove=sha1)
     newdata = {}
     newdata['split_days'] = metadata.split_on_days(
         gtc.get_all_by_path([
             shared.get_git_variables()['username'],
             datetime.now().year,
             datetime.now().month
         ]))
     return jsonify(newdata=newdata)
Exemplo n.º 3
0
def _write_note(note_dict, value, state, **kwargs):
    logging.debug(f'timelog._write_note({note_dict}, {value}, {kwargs})')
    cday = kwargs.get('cday', None)
    if value is not None:
        chour, cminute = _split_time_value(value)
        if cday is not None:
            if state == 'start':
                note_dict['timestamp_start'] = metadata.time(chour=chour,
                                                             cminute=cminute,
                                                             cday=cday)
            else:
                note_dict['timestamp_end'] = metadata.time(chour=chour,
                                                           cminute=cminute,
                                                           cday=cday)
        else:
            if state == 'start':
                note_dict['timestamp_start'] = metadata.time(chour=chour,
                                                             cminute=cminute)
            else:
                note_dict['timestamp_end'] = metadata.time(chour=chour,
                                                           cminute=cminute)
    else:
        if state == 'start':
            note_dict['timestamp_start'] = metadata.time()
        elif state == 'end':
            note_dict['timestamp_end'] = metadata.time()
    if state == 'start':
        gtc.store(target=[
            shared.get_git_variables()['username'],
            datetime.now().year,
            datetime.now().month
        ],
                  content=note_dict)  # Tilfoej ny!
        # gtc.store(target=[shared.get_git_variables()['username'], datetime.now().year, datetime.now().month], remove='74866fd4078fdad62b13a4968087852aec7b0788')
    elif state == 'end':
        gtc.store(target=[
            shared.get_git_variables()['username'],
            datetime.now().year,
            datetime.now().month
        ],
                  append='sha1',
                  content={'timestamp_end': '123'})  # tilfoej s**t tid
    return note_dict
Exemplo n.º 4
0
    def test_submit_to_existing_path(self):
        subprocess.call(['bash', './test/scripts/Setup'],
                        stdout=None,
                        stderr=None)

        shared.set_working_dir('./test/test_env/clone1')
        content1 = {'user': '******', 'something': 'some data'}
        place = ['asd', 'dada']
        gtc.store(target=place, content=content1)
        gtc.push()
        content2 = {'user': '******', 'something': 'some other data'}
        gtc.store(target=place, content=content2)
        gtc.push()
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {
            shared.sha1_gen_dict(content1): content1,
            shared.sha1_gen_dict(content2): content2
        }
        self.assertEqual(gtc.get_all_by_path(place), expected)

        shared.set_working_dir('./test/test_env/origin')
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {
            shared.sha1_gen_dict(content1): content1,
            shared.sha1_gen_dict(content2): content2
        }
        self.assertEqual(gtc.get_all_by_path(place), expected)

        #test append
        shared.set_working_dir('./test/test_env/clone1')
        place = ['asd', 'dada']
        append = shared.sha1_gen_dict(content1)
        append_data = {'more': 'data'}
        gtc.store(target=place, append=append, content=append_data)
        content1.update(append_data)
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {
            shared.sha1_gen_dict(content1): content1,
            shared.sha1_gen_dict(content2): content2
        }
        self.assertEqual(gtc.get_all_by_path(place), expected)

        #test remove
        place = ['asd', 'dada']
        remove = shared.sha1_gen_dict(content2)
        gtc.store(target=place, remove=remove)
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content1): content1}
        self.assertEqual(gtc.get_all_by_path(place), expected)
Exemplo n.º 5
0
    def test_simple(self):
        subprocess.call(['bash', './test/scripts/Setup'],
                        stdout=None,
                        stderr=None)
        try:
            gtc.store()
        except:
            self.assertEqual(str(sys.exc_info()[1]), '1')

        # test commit first time direct to file
        shared.set_working_dir('./test/test_env/clone1')
        content = {'user': '******', 'something': 'some data'}
        place = ['abc']
        gtc.store(target=place, content=content)
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)

        #test with advance path
        shared.set_working_dir('./test/test_env/clone1')
        content = {'user': '******', 'something': 'some data'}
        place = ['asd', 'dada']
        gtc.store(target=place, content=content)
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)

        # test push commit first time
        shared.set_working_dir('./test/test_env/clone1')
        gtc.push()
        shared.set_working_dir('./test/test_env/origin')
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        content = {'user': '******', 'something': 'some data'}
        place = ['abc']
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)

        content = {'user': '******', 'something': 'some data'}
        place = ['asd', 'dada']
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)

        # test fetch first time no ref
        shared.set_working_dir('./test/test_env/clone2')
        gtc.fetch()
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        content = {'user': '******', 'something': 'some data'}
        place = ['abc']
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)

        content = {'user': '******', 'something': 'some data'}
        place = ['asd', 'dada']
        expected = {shared.sha1_gen_dict(content): content}
        self.assertEqual(gtc.get_all_by_path(place), expected)
Exemplo n.º 6
0
    def test_merge_conflict_simple_ref_merge(self):
        # setup test env
        subprocess.call(['bash', './test/scripts/Setup'],
                        stdout=None,
                        stderr=None)
        shared.set_working_dir('./test/test_env/clone1')
        content1 = {'user': '******', 'something': 'some data'}
        place1 = ['asd', 'dada']
        gtc.store(target=place1, content=content1)
        gtc.push()

        # merge different path no history
        shared.set_working_dir('./test/test_env/clone2')
        content2 = {'user': '******', 'something': 'some data'}
        place2 = ['cvb', 'dada']
        gtc.store(target=place2, content=content2)
        gtc.push()

        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content1): content1}
        self.assertEqual(gtc.get_all_by_path(place1), expected)
        expected = {shared.sha1_gen_dict(content2): content2}
        self.assertEqual(gtc.get_all_by_path(place2), expected)

        shared.set_working_dir('./test/test_env/origin')
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content1): content1}
        self.assertEqual(gtc.get_all_by_path(place1), expected)
        expected = {shared.sha1_gen_dict(content2): content2}
        self.assertEqual(gtc.get_all_by_path(place2), expected)

        # merge different path with history
        shared.set_working_dir('./test/test_env/clone1')
        content3 = {'user': '******', 'something': 'some data'}
        place3 = ['asd', 'dada2']
        gtc.store(target=place3, content=content3)
        gtc.fetch()
        gtc.push()
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content1): content1}
        self.assertEqual(gtc.get_all_by_path(place1), expected)
        expected = {shared.sha1_gen_dict(content2): content2}
        self.assertEqual(gtc.get_all_by_path(place2), expected)
        expected = {shared.sha1_gen_dict(content3): content3}
        self.assertEqual(gtc.get_all_by_path(place3), expected)

        shared.set_working_dir('./test/test_env/origin')
        timecommit_name = git_timestore.get_current_ref('refs/time/commits')
        self.assertTrue(timecommit_name is not None)
        expected = {shared.sha1_gen_dict(content1): content1}
        self.assertEqual(gtc.get_all_by_path(place1), expected)
        expected = {shared.sha1_gen_dict(content2): content2}
        self.assertEqual(gtc.get_all_by_path(place2), expected)
        expected = {shared.sha1_gen_dict(content3): content3}
        self.assertEqual(gtc.get_all_by_path(place3), expected)
Exemplo n.º 7
0
    def put(self):
        try:
            json_data = request.get_json(force=True)
            sha1 = json_data['sha1']
            newissue = json_data['issue']
            timestamp_start = json_data['start_time']
            timestamp_end = json_data['end_time']
            tz = metadata.get_tz_info()
            og = gtc.get_all_by_path([
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ])[sha1]
            try:
                issue = og['issue']
            except:
                issue = None
            try:
                if int(issue) != int(newissue):
                    issue = newissue
            except:
                issue = newissue
            timestamp_start = metadata.convert_from_js(timestamp_start, tz)
            timestamp_end = metadata.convert_from_js(timestamp_end, tz)
            if datetime.strptime(timestamp_start,
                                 '%Y-%m-%dT%H:%M') <= datetime.strptime(
                                     timestamp_end, '%Y-%m-%dT%H:%M'):
                time = timestamp_start[11:]
                datestamp = timestamp_start[:10]
                month = datestamp[5:-3]
                date = datestamp[-2:]
                hour = time[:2]
                minute = time[-2:]
                timestamp_start = metadata.time(chour=hour,
                                                cminute=minute,
                                                cday=date,
                                                cmonth=month)
                time = timestamp_end[11:]
                datestamp = timestamp_end[:10]
                month = datestamp[5:-3]
                date = datestamp[-2:]
                hour = time[:2]
                minute = time[-2:]
                timestamp_end = metadata.time(chour=hour,
                                              cminute=minute,
                                              cday=date,
                                              cmonth=month)

            gtc.store(target=[
                shared.get_git_variables()['username'],
                datetime.now().year,
                datetime.now().month
            ],
                      remove=sha1,
                      content={
                          'timestamp_end': timestamp_end,
                          'timestamp_start': timestamp_start,
                          'issue': issue,
                          'user': shared.get_git_variables()['username']
                      })

            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Succes", newdata=newdata)
        except:
            print('CRASH!')
            newdata = {}
            newdata['split_days'] = metadata.split_on_days(
                gtc.get_all_by_path([
                    shared.get_git_variables()['username'],
                    datetime.now().year,
                    datetime.now().month
                ]))
            return jsonify(status="Failed", data=newdata)
Exemplo n.º 8
0
def log_type(state, **kwargs):
    logging.debug(f'timelog.log_type({state}, {kwargs})')
    '''
    Makes our meta data string, that we are gonna use for logging time in git notes.

    Args:
        param1(str): state - if you 'start' the time log or 'end' it
        param2(str): chour - custom hour for the time returned
        param3(str): cminute - custom minute for the time returned

    Return:
        str: Returns a string with meta data including, git username, state (start or end),
        and timestamp with date (from the time method)
    '''
    value = kwargs.get('value', None)
    cday = kwargs.get('date', None)
    username = shared.get_git_variables()['username']
    note_dict = {}
    note_dict['user'] = username
    note_dict['issue'] = shared.get_issue_number()
    # print(state)
    # if metadata.check_correct_order(username, state) is True:
    #     try:
    #         if cday is None:
    #             return _state_types(state, value, note_dict)
    #         return _state_types(state, value, note_dict, cday = cday)
    #     except:
    #         _write_note(note_dict, value, state)
    # else:
    #     return _error(state)
    # return True
    trace = get_trace()
    if trace is not None:
        res = gtc.get_all_by_path(
            [x.strip() for x in trace['path'].split(',')])
        if trace['sha1'] not in res:
            remove_trace()
            trace = None

    # q = input('Would you like to end it before you start a new time? y/n: ').lower().strip()
    if state is 'start':
        if not trace:
            if _custom_check(value) is False:
                return False
            temp_note = _write_note(note_dict, value, state, cday=cday)
            trace = {}
            trace['sha1'] = shared.sha1_gen_dict(temp_note)
            username = shared.get_git_variables()['username']
            year = datetime.now().year
            month = datetime.now().month
            trace['path'] = username + ', ' + str(year) + ', ' + str(month)
            save_trace(trace)
        else:  # trace found
            logging.error('last one not ended')
            #TODO give context of the one open
            while (True):
                q = input(
                    'Would you like to end it before you start a new time? y/n: '
                ).lower().strip()
                if q == 'y' or q == 'yes':
                    #TODO end unfinished, remove trace, store start and save trace
                    time_end = None
                    try:
                        chour, cminute = _split_time_value(value)
                        if cday is not None:
                            time_end = metadata.time(chour=chour,
                                                     cminute=cminute,
                                                     cday=cday)
                        else:
                            time_end = metadata.time(chour=chour,
                                                     cminute=cminute)
                    except:
                        time_end = metadata.time()
                    gtc.store(
                        target=[x.strip() for x in trace['path'].split(',')],
                        append=trace['sha1'],
                        content={'timestamp_end': time_end})
                    remove_trace()
                    temp_note = _write_note(note_dict, value, state, cday=cday)
                    trace = {}
                    trace['sha1'] = shared.sha1_gen_dict(temp_note)
                    username = shared.get_git_variables()['username']
                    year = datetime.now().year
                    month = datetime.now().month
                    trace['path'] = username + ', ' + str(year) + ', ' + str(
                        month)
                    save_trace(trace)
                    break
                elif q == 'n' or q == 'no':
                    #TODO store start and overwrite trace
                    remove_trace()
                    temp_note = _write_note(note_dict, value, state, cday=cday)
                    trace = {}
                    trace['sha1'] = shared.sha1_gen_dict(temp_note)
                    username = shared.get_git_variables()['username']
                    year = datetime.now().year
                    month = datetime.now().month
                    trace['path'] = username + ', ' + str(year) + ', ' + str(
                        month)
                    save_trace(trace)
                    break
    else:
        trace = get_trace()
        time_end = None
        try:
            chour, cminute = _split_time_value(value)
            if cday is not None:
                time_end = metadata.time(chour=chour,
                                         cminute=cminute,
                                         cday=cday)
            else:
                time_end = metadata.time(chour=chour, cminute=cminute)
        except:
            time_end = metadata.time()
        gtc.store(target=[x.strip() for x in trace['path'].split(',')],
                  append=trace['sha1'],
                  content={'timestamp_end': time_end})
        remove_trace()
Exemplo n.º 9
0
def test(args):
    gtc.store(target=[x.strip() for x in args.place.split(',')],
              content=args.content,
              remove=args.remove,
              append=args.append)