Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: eyeo-depup/src/depup.py

Issue 29599579: OffTopic: DependencyUpdater
Left Patch Set: Integrating into codingtools Created Nov. 20, 2017, 2:58 p.m.
Right Patch Set: Created Nov. 27, 2017, 9:40 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # This file is part of Adblock Plus <https://adblockplus.org/>, 3 # This file is part of Adblock Plus <https://adblockplus.org/>,
4 # Copyright (C) 2006-present eyeo GmbH 4 # Copyright (C) 2006-present eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 29 matching lines...) Expand all
40 40
41 from src.vcs import Vcs 41 from src.vcs import Vcs
42 42
43 logging.basicConfig() 43 logging.basicConfig()
44 logger = logging.getLogger('eyeo-depup') 44 logger = logging.getLogger('eyeo-depup')
45 45
46 46
47 class DepUpdate(object): 47 class DepUpdate(object):
48 """The main class used to process dependency updates. 48 """The main class used to process dependency updates.
49 49
50 TODO: CLARIFY ME! 50 DepUpdate provides an argument parser and subcommand routing for the
51 51 commands 'diff', 'issue', 'changes' and 'commit'. Each command may require
52 it's own set of parameters and parse them accordingly.
53
54 When parsing is successufl and all required parameters are provided,
55 DepUpdate will execute the corresponding command and will either print the
56 output to STDOUT or to the given filename.
52 """ 57 """
53 58
54 VCS_EXECUTABLE = ('hg', '--config', 'defaults.log=', '--config', 59 VCS_EXECUTABLE = ('hg', '--config', 'defaults.log=', '--config',
55 'defaults.pull=') 60 'defaults.pull=')
56 ISSUE_NUMBER_REGEX = re.compile(r'\b(issue|fixes)\s+(\d+)\b', re.I) 61 ISSUE_NUMBER_REGEX = re.compile(r'\b(issue|fixes)\s+(\d+)\b', re.I)
57 NOISSUE_REGEX = re.compile(r'^noissue\b', re.I) 62 NOISSUE_REGEX = re.compile(r'^noissue\b', re.I)
58 63
59 def __init__(self, *args): 64 def __init__(self, *args):
60 """Construct a DepUpdate object. 65 """Construct a DepUpdate object.
61 66
62 During initialization, DepUpdate will invoke the appropriate VCS to 67 During initialization, DepUpdate will invoke the appropriate VCS to
63 fetch a list of changes, parse them and (if not otherwise specified) 68 fetch a list of changes, parse them and (if not otherwise specified)
64 get the matching revisions from the mirrored repository. 69 get the matching revisions from the mirrored repository.
65 70
66 Parameters: *args - Passed down to the argparse.ArgumentParser instance 71 Parameters: *args - Passed down to the argparse.ArgumentParser instance
67 72
68 """ 73 """
69 self._cwd = os.getcwd() 74 self._cwd = os.getcwd()
70 75
71 self.root_repo = Vcs.factory(self._cwd)
72
73 self._base_revision = None 76 self._base_revision = None
74 self._parsed_changes = None 77 self._parsed_changes = None
75 self.arguments = None 78 self.arguments = None
76 79
77 self._dep_config = None 80 self._dep_config = None
78 81
79 default_template = os.path.join( 82 default_template = os.path.join(
80 os.path.dirname(os.path.realpath(__file__)), 'templates', 83 os.path.dirname(os.path.realpath(__file__)), 'templates',
81 'default.trac') 84 'default.trac')
82 85
83 # Initialize and run the internal argument parser 86 # Initialize and run the internal argument parser
84 self._make_arguments(default_template, *args) 87 self._make_arguments(default_template, *args)
85 88
86 # Check if root repository is dirty 89 # Check if root repository is dirty
90 self.root_repo = Vcs.factory(self._cwd)
87 if not self.root_repo.repo_is_clean(): 91 if not self.root_repo.repo_is_clean():
88 logger.error('Your repository is dirty') 92 logger.error('Your repository is dirty')
89 exit(1) 93 exit(1)
90 94
91 # Initialize the main VCS and the list of changes 95 # Initialize the main VCS and the list of changes
92 self._main_vcs = Vcs.factory(os.path.join(self._cwd, 96 self._main_vcs = Vcs.factory(os.path.join(self._cwd,
93 self.arguments.dependency)) 97 self.arguments.dependency))
94 self.changes = self._main_vcs.change_list(self.base_revision, 98 self.changes = self._main_vcs.change_list(self.base_revision,
95 self.arguments.new_revision) 99 self.arguments.new_revision)
96 if len(self.changes) == 0: 100 if len(self.changes) == 0:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 # Add the command and options for creating an issue body 185 # Add the command and options for creating an issue body
182 issue_parser = subs.add_parser( 186 issue_parser = subs.add_parser(
183 'issue', parents=[options_parser, advanced_parser], 187 'issue', parents=[options_parser, advanced_parser],
184 help='Render an issue body', 188 help='Render an issue body',
185 description=('Render an issue subject and an issue body, ' 189 description=('Render an issue subject and an issue body, '
186 'according to the given template.')) 190 'according to the given template.'))
187 issue_parser.add_argument( 191 issue_parser.add_argument(
188 '-t', '--template', dest='tmpl_path', 192 '-t', '--template', dest='tmpl_path',
189 default=default_template, 193 default=default_template,
190 help=('The template to use. Defaults to the provided ' 194 help=('The template to use. Defaults to the provided '
191 'default.trac (Used only with -i/--issue).') 195 'default.trac.')
192 ) 196 )
193 197
194 # Add the command for printing a list of changes 198 # Add the command for printing a list of changes
195 subs.add_parser( 199 subs.add_parser(
196 'changes', parents=[options_parser, advanced_parser], 200 'changes', parents=[options_parser, advanced_parser],
197 help='Generate a list of commits between two revisions', 201 help='Generate a list of commits between two revisions',
198 description=('Generate a list of commit hashes and commit ' 202 description=('Generate a list of commit hashes and commit '
199 "messages between the dependency's current " 203 "messages between the dependency's current "
200 'revision and a given new revision.')) 204 'revision and a given new revision.'))
201 205
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if self.arguments.lookup_inotes: 461 if self.arguments.lookup_inotes:
458 self.lookup_integration_notes() 462 self.lookup_integration_notes()
459 463
460 output = action_map[self.arguments.action]() 464 output = action_map[self.arguments.action]()
461 if self.arguments.filename is not None: 465 if self.arguments.filename is not None:
462 with io.open(self.arguments.filename, 'w', encoding='utf-8') as fp: 466 with io.open(self.arguments.filename, 'w', encoding='utf-8') as fp:
463 fp.write(output) 467 fp.write(output)
464 print('Output writen to ' + self.arguments.filename) 468 print('Output writen to ' + self.arguments.filename)
465 else: 469 else:
466 print(output) 470 print(output)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld