示例#1
0
    def check_group(self, group):
        files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
        cmd = ['msgfmt', '-o', os.devnull, '--check-format']
        # Disabled because too many such errors, and not that critical anyway
        # if group == 'calibre':
        #     cmd += ['--check-accelerators=&']

        def check(f):
            p = subprocess.Popen(cmd + [f], stderr=subprocess.PIPE)
            errs = p.stderr.read()
            p.wait()
            return errs

        def check_for_control_chars(f):
            raw = open(f, 'rb').read().decode('utf-8')
            pat = re.compile(type(u'')(r'[\0-\x08\x0b\x0c\x0e-\x1f\x7f\x80-\x9f]'))
            errs = []
            for i, line in enumerate(raw.splitlines()):
                if pat.search(line) is not None:
                    errs.append('There are ASCII control codes on line number: {}'.format(i + 1))
            return '\n'.join(errs)

        for f in files:
            errs = check(f)
            if errs:
                print(f)
                print(errs)
                edit_file(f)
                if check(f):
                    raise SystemExit('Aborting as not all errors were fixed')
            errs = check_for_control_chars(f)
            if errs:
                print(f, 'has ASCII control codes in it')
                print(errs)
                raise SystemExit(1)
示例#2
0
    def check_group(self, group):
        files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
        cmd = ['msgfmt', '-o', os.devnull, '--check-format']
        # Disabled because too many such errors, and not that critical anyway
        # if group == 'calibre':
        #     cmd += ['--check-accelerators=&']

        def check(f):
            p = subprocess.Popen(cmd + [f], stderr=subprocess.PIPE)
            errs = p.stderr.read()
            p.wait()
            return errs

        def check_for_control_chars(f):
            raw = open(f, 'rb').read().decode('utf-8')
            pat = re.compile(ur'[\0-\x08\x0b\x0c\x0e-\x1f\x7f\x80-\x9f]')
            errs = []
            for i, line in enumerate(raw.splitlines()):
                if pat.search(line) is not None:
                    errs.append('There are ASCII control codes on line number: {}'.format(i + 1))
            return '\n'.join(errs)

        for f in files:
            errs = check(f)
            if errs:
                print(f)
                print(errs)
                edit_file(f)
                if check(f):
                    raise SystemExit('Aborting as not all errors were fixed')
            errs = check_for_control_chars(f)
            if errs:
                print(f, 'has ASCII control codes in it')
                print(errs)
                raise SystemExit(1)
示例#3
0
 def run(self, opts):
     self.fhash_cache = {}
     cache = {}
     self.wn_path = os.path.expanduser('~/work/srv/main/static')
     self.has_changelog_check = os.path.exists(self.wn_path)
     try:
         with open(self.cache_file, 'rb') as f:
             cache = json.load(f)
     except OSError as err:
         if err.errno != errno.ENOENT:
             raise
     dirty_files = tuple(f for f in self.get_files()
                         if not self.is_cache_valid(f, cache))
     try:
         for i, f in enumerate(dirty_files):
             self.info('\tChecking', f)
             if self.file_has_errors(f):
                 self.info('%d files left to check' %
                           (len(dirty_files) - i - 1))
                 edit_file(f)
                 if self.file_has_errors(f):
                     raise SystemExit(1)
             cache[f] = self.file_hash(f)
     finally:
         self.save_cache(cache)
示例#4
0
    def check_group(self, group):
        files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
        cmd = ['msgfmt', '-o', os.devnull, '--check-format']
        # Disabled because too many such errors, and not that critical anyway
        # if group == 'calibre':
        #     cmd += ['--check-accelerators=&']

        def check(f):
            p = subprocess.Popen(cmd + [f], stderr=subprocess.PIPE)
            errs = p.stderr.read()
            p.wait()
            return errs

        for f in files:
            errs = check(f)
            if errs:
                print(f)
                print(errs)
                edit_file(f)
                if check(f):
                    raise SystemExit('Aborting as not all errors were fixed')
示例#5
0
    def check_group(self, group):
        files = glob.glob(os.path.join(self.TRANSLATIONS, group, '*.po'))
        cmd = ['msgfmt', '-o', os.devnull, '--check-format']
        # Disabled because too many such errors, and not that critical anyway
        # if group == 'calibre':
        #     cmd += ['--check-accelerators=&']

        def check(f):
            p = subprocess.Popen(cmd + [f], stderr=subprocess.PIPE)
            errs = p.stderr.read()
            p.wait()
            return errs

        for f in files:
            errs = check(f)
            if errs:
                print(f)
                print(errs)
                edit_file(f)
                if check(f):
                    raise SystemExit('Aborting as not all errors were fixed')
示例#6
0
文件: check.py 项目: NiLuJe/calibre
 def run(self, opts):
     self.fhash_cache = {}
     cache = {}
     self.wn_path = os.path.expanduser('~/work/srv/main/static')
     self.has_changelog_check = os.path.exists(self.wn_path)
     try:
         cache = json.load(open(self.cache_file, 'rb'))
     except EnvironmentError as err:
         if err.errno != errno.ENOENT:
             raise
     dirty_files = tuple(f for f in self.get_files() if not self.is_cache_valid(f, cache))
     try:
         for i, f in enumerate(dirty_files):
             self.info('\tChecking', f)
             if self.file_has_errors(f):
                 self.info('%d files left to check' % (len(dirty_files) - i - 1))
                 edit_file(f)
                 if self.file_has_errors(f):
                     raise SystemExit(1)
             cache[f] = self.file_hash(f)
     finally:
         self.save_cache(cache)