style.py (10294:b58f6afe14c5) | style.py (10674:e2f9644a7738) |
---|---|
1#! /usr/bin/env python 2# Copyright (c) 2014 ARM Limited 3# All rights reserved 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 144 unchanged lines hidden (view full) --- 153class StdioUI(UserInterface): 154 def do_prompt(self, prompt, results, default): 155 return raw_input(prompt) or default 156 157 def write(self, string): 158 sys.stdout.write(string) 159 160class Verifier(object): | 1#! /usr/bin/env python 2# Copyright (c) 2014 ARM Limited 3# All rights reserved 4# 5# The license below extends only to copyright in the software and shall 6# not be construed as granting a license to any other intellectual 7# property including but not limited to intellectual property relating 8# to a hardware implementation of the functionality of the software --- 144 unchanged lines hidden (view full) --- 153class StdioUI(UserInterface): 154 def do_prompt(self, prompt, results, default): 155 return raw_input(prompt) or default 156 157 def write(self, string): 158 sys.stdout.write(string) 159 160class Verifier(object): |
161 def __init__(self, ui, repo=None): | 161 def __init__(self, ui, repo): |
162 self.ui = ui 163 self.repo = repo | 162 self.ui = ui 163 self.repo = repo |
164 if repo is None: 165 self.wctx = None | |
166 167 def __getattr__(self, attr): 168 if attr in ('prompt', 'write'): 169 return getattr(self.ui, attr) 170 171 if attr == 'wctx': 172 try: 173 wctx = repo.workingctx() 174 except: 175 from mercurial import context 176 wctx = context.workingctx(repo) 177 self.wctx = wctx 178 return wctx 179 180 raise AttributeError 181 182 def open(self, filename, mode): | 164 165 def __getattr__(self, attr): 166 if attr in ('prompt', 'write'): 167 return getattr(self.ui, attr) 168 169 if attr == 'wctx': 170 try: 171 wctx = repo.workingctx() 172 except: 173 from mercurial import context 174 wctx = context.workingctx(repo) 175 self.wctx = wctx 176 return wctx 177 178 raise AttributeError 179 180 def open(self, filename, mode): |
183 if self.repo: 184 filename = self.repo.wjoin(filename) | 181 filename = self.repo.wjoin(filename) |
185 186 try: 187 f = file(filename, mode) 188 except OSError, msg: 189 print 'could not open file %s: %s' % (filename, msg) 190 return None 191 192 return f 193 194 def skip(self, filename): | 182 183 try: 184 f = file(filename, mode) 185 except OSError, msg: 186 print 'could not open file %s: %s' % (filename, msg) 187 return None 188 189 return f 190 191 def skip(self, filename): |
192 filename = self.repo.wjoin(filename) 193 |
|
195 # We never want to handle symlinks, so always skip them: If the location 196 # pointed to is a directory, skip it. If the location is a file inside 197 # the gem5 directory, it will be checked as a file, so symlink can be 198 # skipped. If the location is a file outside gem5, we don't want to 199 # check it anyway. 200 if os.path.islink(filename): 201 return True 202 return lang_type(filename) not in self.languages --- 239 unchanged lines hidden (view full) --- 442 opt_no_ignore = opts.get('no_ignore', False) 443 ui = MercurialUI(hgui, hgui.verbose, opt_fix_white) 444 445 def prompt(name, func, regions=all_regions): 446 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a') 447 if result == 'a': 448 return True 449 elif result == 'f': | 194 # We never want to handle symlinks, so always skip them: If the location 195 # pointed to is a directory, skip it. If the location is a file inside 196 # the gem5 directory, it will be checked as a file, so symlink can be 197 # skipped. If the location is a file outside gem5, we don't want to 198 # check it anyway. 199 if os.path.islink(filename): 200 return True 201 return lang_type(filename) not in self.languages --- 239 unchanged lines hidden (view full) --- 441 opt_no_ignore = opts.get('no_ignore', False) 442 ui = MercurialUI(hgui, hgui.verbose, opt_fix_white) 443 444 def prompt(name, func, regions=all_regions): 445 result = ui.prompt("(a)bort, (i)gnore, or (f)ix?", 'aif', 'a') 446 if result == 'a': 447 return True 448 elif result == 'f': |
450 func(repo.wjoin(name), regions) | 449 func(name, regions) |
451 452 return False 453 454 455 # Import the match (repository file name matching helper) 456 # function. Different versions of Mercurial keep it in different 457 # modules and implement them differently. 458 try: --- 12 unchanged lines hidden (view full) --- 471 from mercurial import context 472 wctx = context.workingctx(repo) 473 474 files = [ (fn, all_regions) for fn in added ] + \ 475 [ (fn, modregions(wctx, fn)) for fn in modified ] 476 else: 477 files = [ (fn, all_regions) for fn in added + modified + clean ] 478 | 450 451 return False 452 453 454 # Import the match (repository file name matching helper) 455 # function. Different versions of Mercurial keep it in different 456 # modules and implement them differently. 457 try: --- 12 unchanged lines hidden (view full) --- 470 from mercurial import context 471 wctx = context.workingctx(repo) 472 473 files = [ (fn, all_regions) for fn in added ] + \ 474 [ (fn, modregions(wctx, fn)) for fn in modified ] 475 else: 476 files = [ (fn, all_regions) for fn in added + modified + clean ] 477 |
479 whitespace = Whitespace(ui) 480 sorted_includes = SortedIncludes(ui) | 478 whitespace = Whitespace(ui, repo) 479 sorted_includes = SortedIncludes(ui, repo) |
481 for fname, mod_regions in files: 482 if not opt_no_ignore and check_ignores(fname): 483 continue 484 | 480 for fname, mod_regions in files: 481 if not opt_no_ignore and check_ignores(fname): 482 continue 483 |
485 fpath = joinpath(repo.root, fname) 486 487 if whitespace.apply(fpath, prompt, mod_regions): | 484 if whitespace.apply(fname, prompt, mod_regions): |
488 return True 489 | 485 return True 486 |
490 if sorted_includes.apply(fpath, prompt, mod_regions): | 487 if sorted_includes.apply(fname, prompt, mod_regions): |
491 return True 492 493 return False 494 495def do_check_format(hgui, repo, **args): 496 ui = MercurialUI(hgui, hgui.verbose, auto) 497 498 modified, added, removed, deleted, unknown, ignore, clean = repo.status() --- 117 unchanged lines hidden --- | 488 return True 489 490 return False 491 492def do_check_format(hgui, repo, **args): 493 ui = MercurialUI(hgui, hgui.verbose, auto) 494 495 modified, added, removed, deleted, unknown, ignore, clean = repo.status() --- 117 unchanged lines hidden --- |