def parse_and_create_stats(self):
     """parses all the po files in the test directory into memory, using store_file, which creates Stats"""
     count = 0
     indexing.HAVE_INDEXER = False
     for dirpath, subdirs, filenames in os.walk(self.po_dir, topdown=False):
         for name in filenames:
             pofilename = os.path.join(dirpath, name)
             parsedfile = store_file.store_file(pofilename=pofilename)
             count += len(parsedfile.units)
     print "stats on %d units" % count
示例#2
0
 def parse_and_create_stats(self):
     """parses all the po files in the test directory into memory, using store_file, which creates Stats"""
     count = 0
     indexing.HAVE_INDEXER = False
     for dirpath, subdirs, filenames in os.walk(self.po_dir, topdown=False):
         for name in filenames:
             pofilename = os.path.join(dirpath, name)
             parsedfile = store_file.store_file(pofilename=pofilename)
             count += len(parsedfile.units)
     print "stats on %d units" % count
def processfile(filename):
    dummyproject = projects.DummyProject(os.path.dirname(filename), None)
    pofile = store_file.store_file(dummyproject, os.path.basename(filename))
    pofile.readpofile()
    conflictitems = []
    for item in pofile.statistics.getstats()['total']:
        poentry = pofile.units[item]
        if poentry.hasplural():
            targets = poentry.target.strings
        else:
            targets = [poentry.target]
        for target in targets:
            if conflictmarker in target:
                conflictitems.append((item, targets))
                break
    for (item, targets) in conflictitems:
        replacetargets = []
        for target in targets:
            if conflictmarker not in target:
                replacetargets.append(target)
                continue
            lines = target.split('\n')
            parts = []
            (marker, part) = ('', '')
            for line in lines:
                if line.startswith(conflictmarker)\
                     and line.endswith(conflictmarker):
                    if marker or part:
                        parts.append((marker, part))
                    marker = line[len(conflictmarker):-len(conflictmarker)]
                    part = ''
                else:
                    part += line
            if marker or part:
                parts.append((marker, part))
            for (marker, part) in parts:
                pofile.addsuggestion(item, part, marker.strip())
            replacetargets.append('')
        newvalues = {'target': replacetargets}
        pofile.updateunit(item, newvalues, None, None)
def processfile(filename):
    dummyproject = projects.DummyProject(os.path.dirname(filename), None)
    pofile = store_file.store_file(dummyproject, os.path.basename(filename))
    pofile.readpofile()
    conflictitems = []
    for item in pofile.statistics.getstats()['total']:
        poentry = pofile.units[item]
        if poentry.hasplural():
            targets = poentry.target.strings
        else:
            targets = [poentry.target]
        for target in targets:
            if conflictmarker in target:
                conflictitems.append((item, targets))
                break
    for (item, targets) in conflictitems:
        replacetargets = []
        for target in targets:
            if conflictmarker not in target:
                replacetargets.append(target)
                continue
            lines = target.split('\n')
            parts = []
            (marker, part) = ('', '')
            for line in lines:
                if line.startswith(conflictmarker)\
                     and line.endswith(conflictmarker):
                    if marker or part:
                        parts.append((marker, part))
                    marker = line[len(conflictmarker):-len(conflictmarker)]
                    part = ''
                else:
                    part += line
            if marker or part:
                parts.append((marker, part))
            for (marker, part) in parts:
                pofile.addsuggestion(item, part, marker.strip())
            replacetargets.append('')
        newvalues = {'target': replacetargets}
        pofile.updateunit(item, newvalues, None, None)