Example #1
0
def write(s, end='\n'):
    s = unistr(s) + unistr(end)
    s = s.encode('utf-8')
    if PY2:
        sys.stdout.write(s)
    else:
        sys.stdout.buffer.write(s)
def safe_replace(text, a, b):
    a = unistr(a)
    b = unistr(b)
    result = text.replace(a, b)
    if result == text:
        raise ValueError(
            "Error: replacing '%s' with '%s' did not change the text." %
            (a, b))
    return result
def examine_projects(args):
    start_index = args.start_index
    max_files = args.max_files

    filenames = filenames_to_examine()
    filenames = filenames[start_index:]
    if max_files is not None:
        filenames = filenames[:max_files]

    total_numbytes = 0
    total_parsetime = 0
    total_unparsetime = 0
    num_files = 0
    num_successes = 0
    t0 = time.time()
    for idx, result in enumerate(run_lint(args, filenames)):
        num_files += 1
        globalidx = start_index + idx
        try:
            tbtext = None
            if isinstance(result, ExcInfo):
                t, v, tb = result.exc_info
                if not isinstance(tb, types.TracebackType):
                    tbtext = tb
                    tb = None
                reraise(t, v, tb)

            sys.stdout.write("%d " % globalidx)
            sys.stdout.flush()
            handle_result(args, result.success, result.text, result.filename)
            if result.success:
                num_successes += 1
                if args.reportstats:
                    total_numbytes += result.numbytes
                    total_parsetime += result.parsetime
                    total_unparsetime += result.unparsetime
        except IOError as e:
            write('\n%d "%s" failed: %s' %
                  (globalidx, unistr(filenames[idx]), repr(e)))
        except Exception as e:
            write('\n%d "%s" failed:' % (globalidx, unistr(filenames[idx])))
            if tbtext is not None:
                print(tbtext)
            else:
                traceback.print_exc()

    if args.reportstats and num_successes > 0:
        tdelta = time.time() - t0
        print("\nparse rate:%9d Bps    unparse rate:%9d Bps (per core)" %
              (total_numbytes / total_parsetime,
               total_numbytes / total_unparsetime))
        print("Processed %d Bps, avg. time per project: %f" %
              (total_numbytes / tdelta, tdelta / num_successes))
    if args.reportstats:
        print("Processed %d project files of which %d were unsuccessful" %
              (num_files, num_files - num_successes))
def examine_projects(args):
    start_index = args.start_index
    max_files = args.max_files

    filenames = filenames_to_examine()
    filenames = filenames[start_index:]
    if max_files is not None:
        filenames = filenames[:max_files]

    total_numbytes = 0
    total_parsetime = 0
    total_unparsetime = 0
    num_files = 0
    num_successes = 0
    t0 = time.time()
    for idx, result in enumerate(run_lint(args, filenames)):
        num_files += 1
        globalidx = start_index + idx
        try:
            tbtext = None
            if isinstance(result, ExcInfo):
                t, v, tb = result.exc_info
                if not isinstance(tb, types.TracebackType):
                    tbtext = tb
                    tb = None
                reraise(t, v, tb)

            sys.stdout.write("%d " % globalidx)
            sys.stdout.flush()
            handle_result(args, result.success, result.text, result.filename)
            if result.success:
                num_successes += 1
                if args.reportstats:
                    total_numbytes += result.numbytes
                    total_parsetime += result.parsetime
                    total_unparsetime += result.unparsetime
        except IOError as e:
            write('\n%d "%s" failed: %s' % (globalidx, unistr(filenames[idx]), repr(e)))
        except Exception as e:
            write('\n%d "%s" failed:' % (globalidx, unistr(filenames[idx])))
            if tbtext is not None:
                print(tbtext)
            else:
                traceback.print_exc()

    if args.reportstats and num_successes > 0:
        tdelta = time.time() - t0
        print("\nparse rate:%9d Bps    unparse rate:%9d Bps (per core)" % (total_numbytes / total_parsetime, total_numbytes / total_unparsetime))
        print("Processed %d Bps, avg. time per project: %f" % (total_numbytes / tdelta, tdelta / num_successes))
    if args.reportstats:
        print("Processed %d project files of which %d were unsuccessful" % (num_files, num_files - num_successes))
Example #5
0
    def test_space_in_unquoted(self):
        prj, filename = read_mini_project()
        pos = prj.find('DeploymentPostprocessing')
        prj = prj[:pos] + ' ' + prj[pos:]

        for format, parsertype in [(None, 'normal'), ('xcode', 'fast'),
                                   ('xcode', 'classic')]:
            buf = StringIO()
            root, parseinfo = parse(prj,
                                    format=format,
                                    parsertype=parsertype,
                                    report=True,
                                    fp=buf)
            self.assertIsNone(root)
            report = unistr(buf.getvalue())

            if parsertype == 'fast':
                self.assertTrue(
                    report.find('Error: parsing Xcode plist via JSON failed')
                    >= 0)
            else:
                self.assertEqual(
                    report, 'File <stdin>, line 21, column 24\n'
                    '\t\t\trunOnlyFor DeploymentPostprocessing = 1;\n'
                    '\t\t\t           ^~~~~~~~~~~~~~~~~~~~~~~~\n'
                    'Error: parsing Xcode plist classically failed\n')
Example #6
0
def rel(filename):
    fn = os.path.join(here(), unistr(filename))
    try:
        if os.path.exists(fn):
            return fn
    except UnicodeEncodeError:
        pass
    return findfile(fn)
def rel(filename):
    fn = os.path.join(here(), unistr(filename))
    try:
        if os.path.exists(fn):
            return fn
    except UnicodeEncodeError:
        pass
    return findfile(fn)
    def test_space_in_unquoted(self):
        prj, filename = read_mini_project()
        pos = prj.find('DeploymentPostprocessing')
        prj = prj[:pos] + ' ' + prj[pos:]

        for format, parsertype in [(None, 'normal'), ('xcode', 'fast'), ('xcode', 'classic')]:
            buf = StringIO()
            root, parseinfo = parse(prj, format=format, parsertype=parsertype,
                                 report=True, fp=buf)
            self.assertIsNone(root)
            report = unistr(buf.getvalue())

            if parsertype == 'fast':
                self.assertTrue(report.find('Error: parsing Xcode plist via JSON failed') >= 0)
            else:
                self.assertEqual(report, 'File <stdin>, line 21, column 24\n'
                                         '\t\t\trunOnlyFor DeploymentPostprocessing = 1;\n'
                                         '\t\t\t           ^~~~~~~~~~~~~~~~~~~~~~~~\n'
                                         'Error: parsing Xcode plist classically failed\n')
def write(s='', end='\n'):
    s = unistr(s) + unistr(end)
    s = s.encode('utf-8')
    sys.stdout.write(s)
Example #10
0
def read_project(relpath):
    filename = rel(relpath)
    prj = read_file(filename)
    prj = unistr(prj)
    return prj, filename
Example #11
0
def read_project(relpath):
    filename = rel(relpath)
    prj = read_file(filename)
    prj = unistr(prj)
    return prj, filename
def write(s='', end='\n'):
    s = unistr(s) + unistr(end)
    s = s.encode('utf-8')
    sys.stdout.write(s)