def test_rappor():
    responder = Responder()
    reviewer = Reviewer()
    num_responders = 1000
    num_choices = 20
    real_responses = [0] * num_choices
    random_responses = [0] * num_choices
    real_responses_per = [0] * num_choices
    estimated_responses_per = [0] * num_choices
    total_random = 0
    print("")
    for x in range(num_responders):
        real_value = int(round(normalvariate(10, 1), 0))
        real_value = min(num_choices - 1, real_value)
        real_value = max(0, real_value)
        real_responses[real_value] += 1
        response = responder._generate_response(num_choices, real_value)
        for y in range(num_choices):
            random_responses[y] += response[y]

    estimated_responses = reviewer._estimate_responses(random_responses,
                                                       num_responders)
    for y in range(num_choices):
        real_responses_per[y] = round(real_responses[y] / num_responders,
                                      4) * 100
        estimated_responses_per[y] = estimated_responses[y] * 100
    print(["{0:0.2f}".format(i) for i in real_responses_per])
    print(["{0:0.2f}".format(i) for i in estimated_responses_per])

    assert (True)
Example #2
0
 def test_intervals_4(self):
     reviewer = Reviewer(FakeCollection(4, 1))
     reviewer.init()
     self.assertEqual({
         'again': 'interval_1',
         'easy': 'interval_4',
         'good': 'interval_3',
         'hard': 'interval_2',
     },reviewer.intervals())
Example #3
0
def main(argv):
    note_parser = NoteParser()
    note_cards = note_parser.parse_notes(argv[0])  # Returns NoteCards instance
    # print("YEET\n\n\n")
    # note_cards.print_cards()

    reviewer = Reviewer(note_cards)
    reviewer.review(True, True)
    return
def main():
    parser = argparse.ArgumentParser(description='Get related patches')
    parser.add_argument('--git-dir',
                        default=None,
                        help='Path to git directory')
    parser.add_argument('--verbose', help='print commits', action='store_true')
    parser.add_argument('--chatty', help='print diffs', action='store_true')
    parser.add_argument('--commit',
                        help='commit hash to find related patches',
                        required=True)
    args = parser.parse_args()

    setup_logging(args)

    reviewer = Reviewer(args.verbose, args.chatty, git_dir=args.git_dir)
    links = reviewer.get_links_from_local_sha(args.commit)

    series = None
    for l in reversed(links):
        logger.debug('Trying patchwork link {}'.format(l))
        parsed = urllib.parse.urlparse(l)

        m = re.match('(.*?)/patch/([^/]*)/?', parsed.path)
        if not m:
            continue
        pw = TrollConfigPatchwork('generated', parsed.netloc, m.group(1),
                                  False)

        logger.debug('Trying parsed patchwork link {}'.format(pw))
        p = PatchworkPatch([pw], l)
        series = p.get_series()
        if series:
            break

    if not series:
        logger.error('Could not find series for patch')
        return 1

    logger.info('Found series: {}'.format(series.url.geturl()))
    patches = series.get_patch_subjects()
    for p in patches:
        logger.info(' Find commits for: {}'.format(p))
        commit = reviewer.get_commit_from_subject(
            p, surrounding_commit=args.commit)
        if not commit:
            logger.warning('Could not find commit for {}'.format(p))
        for c in commit:
            logger.info('   Found: {}'.format(c))
Example #5
0
  def process_changes(self, project, changes):
    rev = Reviewer(git_dir=project.local_repo, verbose=self.config.verbose,
                   chatty=self.config.chatty)
    ret = 0
    for c in changes:
      ignore = False
      for b in project.ignore_branches:
        if re.match(b, c.branch):
          ignore = True
          break
      if ignore:
        if self.config.chatty:
          logger.debug('Ignoring change {}'.format(c))
        self.add_change_to_ignore_list(c)
        continue

      try:
        result = self.process_change(project, rev, c)
        if result:
          self.do_review(project, c, result)
          ret += 1
        self.add_change_to_ignore_list(c)
      except GerritFetchError as e:
        logger.error('Gerrit fetch failed, will retry, {}'.format(c.url()))
        logger.exception('Exception: {}'.format(e))
        # Don't add change to ignore list, we want to retry next time
      except Exception as e:
        logger.error('Exception processing change {}'.format(c.url()))
        logger.exception('Exception: {}'.format(e))
        self.add_change_to_ignore_list(c)

    return ret
Example #6
0
def main():
    parser = argparse.ArgumentParser(
        description='Auto review UPSTREAM patches')
    parser.add_argument('--start',
                        help='commit hash to start from',
                        required=True)
    parser.add_argument('--prefix', default='UPSTREAM', help='subject prefix')
    parser.add_argument('--verbose', help='print commits', action='store_true')
    parser.add_argument('--chatty', help='print diffs', action='store_true')
    args = parser.parse_args()

    proc = subprocess.check_output(
        ['git', 'log', '--oneline',
         '%s^..' % args.start])

    regex = re.compile('([0-9a-f]*) (%s): ' % (args.prefix), flags=re.I)
    ret = 0
    reviewer = Reviewer(args.verbose, args.chatty)
    for l in reversed(proc.decode('UTF-8').split('\n')):
        this_ret = 0
        m = regex.match(l)
        if m:
            this_ret = review_change(reviewer, m.group(1))
        ret += this_ret

    return ret
def main():
    parser = argparse.ArgumentParser(description='Get related patches')
    parser.add_argument('--git-dir',
                        default=None,
                        help='Path to git directory')
    parser.add_argument('--verbose', help='print commits', action='store_true')
    parser.add_argument('--chatty', help='print diffs', action='store_true')
    parser.add_argument('--commit',
                        help='commit hash to find related patches',
                        required=True)
    args = parser.parse_args()

    setup_logging(args)

    reviewer = Reviewer(args.verbose, args.chatty, git_dir=args.git_dir)
    links = reviewer.get_links_from_local_sha(args.commit)

    series = None
    for l in reversed(links):
        p = PatchworkPatch(l)
        series = p.get_series()
        if series:
            break

    if not series:
        logger.error('Could not find series for patch')
        return 1

    logger.info('Found series: {}'.format(series.url.geturl()))
    patches = series.get_patch_subjects()
    for p in patches:
        logger.info(' Find commits for: {}'.format(p))
        commit = reviewer.get_commit_from_subject(
            p, surrounding_commit=args.commit)
        if not commit:
            logger.warn('Could not find commit for {}'.format(p))
        for c in commit:
            logger.info('   Found: {}'.format(c))
Example #8
0
 def setUp(self):
     testdata_dir = os.path.join(os.path.dirname(__file__),'testdata')
     
     # clean workdir for each test
     workdir = os.path.join('/tmp','reviewer')
     if os.path.exists(workdir):
         shutil.rmtree(workdir)
     os.mkdir(workdir)
     src_file = os.path.join(testdata_dir,'changeset.dev')
     data_file = os.path.join(workdir,'changeset.dev')
     shutil.copy(src_file, data_file)
     
     # instatiate reviewer
     self.reviewer = Reviewer(
         trac_env=os.path.join(testdata_dir,'trac_env'),
         repo_dir=os.path.join(testdata_dir,'myrepo'),
         target_ref="master",
         data_file=data_file)
Example #9
0
    def process_changes(self, changes):
        rev = Reviewer(git_dir=self.args.git_dir,
                       verbose=self.args.verbose,
                       chatty=self.args.chatty)
        ret = 0
        for c in changes:
            if self.args.verbose:
                print('Processing change {}'.format(c.url()))

            # Blacklist if we've already reviewed this revision
            for m in c.messages:
                if m.tag == self.tag and m.revision_num == c.current_revision.number:
                    self.add_change_to_blacklist(c)

            # Find a reviewer and blacklist if not found
            reviewer = None
            if FromlistChangeReviewer.can_review_change(c):
                reviewer = FromlistChangeReviewer(rev, c, self.args.dry_run)
            elif FromgitChangeReviewer.can_review_change(c):
                reviewer = FromgitChangeReviewer(rev, c, self.args.dry_run)
            elif UpstreamChangeReviewer.can_review_change(c):
                reviewer = UpstreamChangeReviewer(rev, c, self.args.dry_run)
            if not reviewer:
                self.add_change_to_blacklist(c)
                continue

            force_review = self.args.force_cl or self.args.force_all
            if not force_review and self.is_change_in_blacklist(c):
                continue

            result = reviewer.review_patch()
            if result:
                self.do_review(c, result)
                ret += 1

            self.add_change_to_blacklist(c)

        return ret
Example #10
0
class Converter:
	def __init__(self):
		self.builder = Builder()
		self.renderer = Render()
		self.reviewer = Reviewer()
		return

	def learn(self, image):
		self.builder.init()
		self.renderer.init()
		scene = self.builder.get_scene()		
		earlier = self.renderer.render(scene_1)		

		while Ture:

			maks = self.builder.step(earlier)
			later = self.renderer.render(scene)
			reverd = self.reviewer.review(image, earlier, later, mask)
			self.builder.learn(reverd)
			later = earlier

			if self.reviewer.done:
				break
Example #11
0
 def test_get_question_some(self):
     reviewer = Reviewer(FakeCollection(3, 1))
     reviewer.init()
     self.assertEqual('fake question', reviewer.get_question())
Example #12
0
 def test_is_finished_false(self):
     reviewer = Reviewer(FakeCollection(3, 1))
     reviewer.init()
     self.assertEqual(False, reviewer.is_finished())
Example #13
0
	def __init__(self):
		self.builder = Builder()
		self.renderer = Render()
		self.reviewer = Reviewer()
		return
Example #14
0
from ctfd import CTFd
from user import User
from manager import Manager
from reviewer import Reviewer

ctf = CTFd("https://redpwn.net", 'redpwn2019')
ctf.get_CTFd_sitemap()
ctf.get_CTFd_endpoints()

player = User(ctf)
player.login()

ctf.challenges = player.get_challenges()

manager = Manager(ctf, player)
manager.download_all_challenges_files()
manager.add_all_challenges_description()

reviewer = Reviewer(ctf)
reviewer.init_chall_review()
reviewer.review_challs()
Example #15
0
class TestReviewer(unittest.TestCase):
    
    def setUp(self):
        testdata_dir = os.path.join(os.path.dirname(__file__),'testdata')
        
        # clean workdir for each test
        workdir = os.path.join('/tmp','reviewer')
        if os.path.exists(workdir):
            shutil.rmtree(workdir)
        os.mkdir(workdir)
        src_file = os.path.join(testdata_dir,'changeset.dev')
        data_file = os.path.join(workdir,'changeset.dev')
        shutil.copy(src_file, data_file)
        
        # instatiate reviewer
        self.reviewer = Reviewer(
            trac_env=os.path.join(testdata_dir,'trac_env'),
            repo_dir=os.path.join(testdata_dir,'myrepo'),
            target_ref="master",
            data_file=data_file)
    
    def test_is_complete__changeset1(self):
        changeset1 = '8bebe6d50698dccb68586042e3e94de4aecba945'
        self.assertTrue(self.reviewer.is_complete(changeset1))

    def test_is_complete__changeset2(self):
        changeset2 = 'd57f050a265b303ef1748a26cecb71d9e9ab92b9'
        self.assertTrue(self.reviewer.is_complete(changeset2))

    def test_is_complete__changeset3(self):
        changeset3 = '71cd80944c7c8cdeff9f394b493a372b2b70ebb1'
        self.assertFalse(self.reviewer.is_complete(changeset3))
    
    def test_get_next_changeset__initial(self):
        # expect changeset 3 because ticket #2 is last fully reviewed ticket
        actual = self.reviewer.get_next_changeset() # changeset 3
        expected = 'd57f050a265b303ef1748a26cecb71d9e9ab92b9'
        self.assertEqual(actual,expected)
        self.assertEqual(self.reviewer.get_current_changeset(),expected)
    
    def test_get_next_changeset__initial_no_save(self):
        # expect changeset 3 because ticket #2 is last fully reviewed ticket
        actual = self.reviewer.get_next_changeset(save=False) # changeset 3
        expected = 'd57f050a265b303ef1748a26cecb71d9e9ab92b9'
        self.assertEqual(actual,expected)
        self.assertNotEqual(self.reviewer.get_current_changeset(),expected)
    
    def test_get_next_changeset__at_next(self):
        data = '{"current": "d57f050a265b303ef1748a26cecb71d9e9ab92b9"}'
        open(self.reviewer.data_file,'w').write(data)
        actual = self.reviewer.get_next_changeset() # changeset 3
        expected = 'd57f050a265b303ef1748a26cecb71d9e9ab92b9'
        self.assertEqual(actual,expected)
        self.assertEqual(self.reviewer.get_current_changeset(),expected)
    
    def test_get_next_changeset__at_last(self):
        data = '{"current": "82555dc3c5960646e60df09fb33ab288f209a65b"}'
        open(self.reviewer.data_file,'w').write(data)
        expected = self.reviewer.get_next_changeset() # changeset 4
        self.assertEqual(expected,'82555dc3c5960646e60df09fb33ab288f209a65b')
    
    def test_get_review__initial(self):
        # ensure this method doesn't go away
        expected = '71cd80944c7c8cdeff9f394b493a372b2b70ebb1'
        review = self.reviewer.get_review(expected)
        self.assertEqual(review.changeset,expected)
    
    def test_get_blocking_changeset__initial(self):
        # expect changeset 3 because ticket #2 is last fully reviewed ticket
        actual = self.reviewer.get_blocking_changeset() # changeset 3
        expected = '71cd80944c7c8cdeff9f394b493a372b2b70ebb1'
        self.assertEqual(actual,expected)
    
    def test_get_blocked_tickets__initial(self):
        actual = self.reviewer.get_blocked_tickets()
        self.assertEqual([t.id for t in actual],[2,3])
    
    def test_get_blocked_tickets__at_second_changeset(self):
        data = '{"current": "71cd80944c7c8cdeff9f394b493a372b2b70ebb1"}'
        open(self.reviewer.data_file,'w').write(data)
        actual = self.reviewer.get_blocked_tickets()
        self.assertEqual(len(actual),1)
        self.assertEqual(actual[0].id,3)
        expected = time.mktime(time.strptime("Wed May 16 11:13:48 2012","%a %B %d %H:%M:%S %Y"))
        self.assertEqual(actual[0].first_changeset_when,long(expected*1000000)) # changeset 4
Example #16
0
 def test_current_deck(self):
     reviewer = Reviewer(FakeCollection(3, 1))
     reviewer.init()
     self.assertEqual('deck1', reviewer.current_deck())
Example #17
0
 def test_is_finished_true(self):
     reviewer = Reviewer(FakeCollection(None, 1))
     reviewer.init()
     self.assertEqual(True, reviewer.is_finished())
Example #18
0
 def test_get_question_none(self):
     reviewer = Reviewer(FakeCollection(None, 1))
     reviewer.init()
     self.assertEqual(None, reviewer.get_question())
Example #19
0
 def test_intervals_none(self):
     reviewer = Reviewer(FakeCollection(None, 1))
     reviewer.init()
     self.assertEqual({}, reviewer.intervals())
Example #20
0
 def test_list_decks(self):
     reviewer = Reviewer(FakeCollection(3, 1))
     reviewer.init()
     self.assertEqual([{'deckid': 1, 'deckname': 'deck1'}, {'deckid': 2, 'deckname': 'deck2'}], reviewer.list_decks())
Example #21
0
 def test_answer_button_list_case_4(self):
     reviewer = Reviewer(FakeCollection(None, 1))
     reviewer.init()
     self.assertEqual(((1, 'Again'), (2, 'Good')), reviewer.answer_button_list())
Example #22
0
 def test_answer_button_list_case_3(self):
     reviewer = Reviewer(FakeCollection(4, 1))
     reviewer.init()
     self.assertEqual(((1, 'Again'), (2, 'Hard'), (3, 'Good'), (4, 'Easy')), reviewer.answer_button_list())
Example #23
0
 def test_remaining_none(self):
     reviewer = Reviewer(FakeCollection(None, 0))
     reviewer.init()
     self.assertEqual({'new': 1, 'now': None, 'learning': 2, 'to_review': 3}, reviewer.remaining())
Example #24
0
 def test_remaining_to_review(self):
     reviewer = Reviewer(FakeCollection(2, 2))
     reviewer.init()
     self.assertEqual({'new': 1, 'now': 'to_review', 'learning': 2, 'to_review': 3}, reviewer.remaining())
Example #25
0
 def test_buttons(self):
     reviewer = Reviewer(FakeCollection(2, 1))
     reviewer.init()
     self.assertEqual(['again', 'good'], reviewer.buttons())
Example #26
0
 def test_intervals_2(self):
     reviewer = Reviewer(FakeCollection(2, 1))
     reviewer.init()
     self.assertEqual({'again': 'interval_1', 'good': 'interval_2'}, reviewer.intervals())
Example #27
0
    def process_changes(self, prefix, changes):
        rev = Reviewer(git_dir=self.args.git_dir,
                       verbose=self.args.verbose,
                       chatty=self.args.chatty)
        num_changes = len(changes)
        cur_change = 1
        line_feed = False
        ret = False
        for c in changes:
            cur_rev = c.current_revision

            if self.args.chatty:
                print('Processing change {}'.format(c.url()))
            elif self.args.verbose:
                sys.stdout.write('{}Processing change {}/{}'.format(
                    '\r' if line_feed else '', cur_change, num_changes))
                cur_change += 1

            line_feed = True

            if c in self.blacklist:
                continue

            if not c.subject.startswith(prefix):
                continue

            skip = False
            for m in c.messages:
                if m.tag == self.tag and m.revision_num == cur_rev.number:
                    skip = True
            if skip and not self.args.force_cl:
                continue

            ret = True
            line_feed = False
            if self.args.verbose:
                print('')

            gerrit_patch = rev.get_commit_from_remote('cros', cur_rev.ref)

            if prefix == 'FROMLIST':
                upstream_patchworks = rev.get_am_from_from_patch(gerrit_patch)
                if not upstream_patchworks:
                    self.handle_missing_am_review(c, prefix)
                    continue

                upstream_patch = None
                for u in reversed(upstream_patchworks):
                    try:
                        upstream_patch = rev.get_commit_from_patchwork(u)
                        break
                    except:
                        continue

                if not upstream_patch:
                    self.print_error(
                        'ERROR: patch missing from patchwork, or patchwork host '
                        'not whitelisted for {} ({})\n'.format(
                            c, upstream_patchworks))
                    self.blacklist.append(c)
                    continue
            else:
                upstream_shas = rev.get_cherry_pick_shas_from_patch(
                    gerrit_patch)
                if not upstream_shas:
                    self.handle_missing_hash_review(c, prefix)
                    continue

                upstream_patch = None
                upstream_sha = None
                for s in reversed(upstream_shas):
                    try:
                        upstream_patch = rev.get_commit_from_sha(s)
                        upstream_sha = s
                        break
                    except:
                        continue

                if not upstream_patch:
                    self.print_error(
                        'ERROR: SHA missing from git for {} ({})\n'.format(
                            c, upstream_shas))
                    self.blacklist.append(c)
                    continue

            if prefix != 'FROMLIST':
                fixes_ref = rev.find_fixes_reference(upstream_sha)
            else:
                fixes_ref = None

            result = rev.compare_diffs(upstream_patch, gerrit_patch)

            fields = {'sob': False, 'bug': False, 'test': False}
            sob_re = re.compile('Signed-off-by:\s+{}'.format(
                cur_rev.uploader_name))
            for l in cur_rev.commit_message.splitlines():
                if l.startswith('BUG='):
                    fields['bug'] = True
                    continue
                if l.startswith('TEST='):
                    fields['test'] = True
                    continue
                if sob_re.match(l):
                    fields['sob'] = True
                    continue
            if not fields['bug'] or not fields['test'] or not fields['sob']:
                self.handle_missing_fields_review(c, fields, result, fixes_ref)
                continue

            if len(result) == 0:
                self.handle_successful_review(c, prefix, fixes_ref)
                continue

            self.handle_unsuccessful_review(c, prefix, result, fixes_ref)

        if self.args.verbose:
            print('')

        return ret
Example #28
0
 def test_buttons_case_3(self):
     reviewer = Reviewer(FakeCollection(4, 1))
     reviewer.init()
     self.assertEqual(['again', 'hard', 'good', 'easy'], reviewer.buttons())
Example #29
0
 def test_buttons_case_4(self):
     reviewer = Reviewer(FakeCollection(None, 1))
     reviewer.init()
     self.assertEqual([], reviewer.buttons())
Example #30
0
 def test_get_answer_some(self):
     reviewer = Reviewer(FakeCollection(3, 1))
     reviewer.init()
     self.assertEqual('fake answer', reviewer.get_answer())