Changeset 3119


Ignore:
Timestamp:
Nov 1, 2016, 7:37:58 PM (2 years ago)
Author:
Александър Шопов
Message:

stats.py: порт към Python3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/xml-stats/stats.py

    r3093 r3119  
    1 #!/usr/bin/python
     1#!/usr/local/bin/python3
    22# -*- coding: utf-8 -*-
    33
    4 from __future__ import unicode_literals, print_function
    5 
    6 import urllib2 as u2
     4import urllib.request as r
    75import xml.etree.ElementTree as ET
    86import collections as col
    9 import sys, codecs, locale
    10 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
     7import sys
     8
    119
    1210Stat = col.namedtuple('Stat', ['count', 'name', 'branch', 'work',
     
    2624def get_versions():
    2725    versions_url = 'https://l10n.gnome.org/releases/xml'
    28     versions_data = u2.urlopen(versions_url)
    29 
     26    versions_data = r.urlopen(versions_url)
    3027    versions_tree = ET.parse(versions_data)
    3128    versions_root = versions_tree.getroot()
     
    3835def get_stats(version):
    3936    stats_url = 'https://l10n.gnome.org/languages/bg/{}/xml'.format(version)
    40     stats_data = u2.urlopen(stats_url)
     37    stats_data = r.urlopen(stats_url)
    4138    stats_tree = ET.parse(stats_data)
    4239    stats_root = stats_tree.getroot()
     
    8380    sum_work = 0
    8481    sum_total = 0
    85 
    8682    for s in stats:
    8783        name = max(name, len(s.name))
     
    9288        sum_work = sum_work + s.work
    9389        sum_total = sum_total + s.total
    94 
    9590    max_len = Stat(count=len(str(len(stats))), name=name, branch=branch,
    9691                   translated=len(str(sum_translated)), fuzzy=len(str(sum_fuzzy)),
     
    107102    return '├' + inner + '┤'
    108103
     104
    109105def start(s):
    110106    inner = '┬'.join(['─' * (f + 1) for f in s])
    111107    return '┌' + inner + '┐'
    112108
     109
    113110def end(s):
    114111    inner = '┴'.join(['─' * (f + 1) for f in s])
    115112    return '└' + inner + '┘'
     113
    116114
    117115def ellipsis(s):
     
    127125        part = getattr(str(s[i]), method_name)(width)[:width]
    128126        args.append(part)
    129 
    130127    result = '│{0}│{1}│{2}│{3}│{4}│{5}│{6}│{7}│'.format(*tuple(args))
    131128    return result
     
    139136        part = getattr(titles[i][0], method_name)(width)[:width]
    140137        args.append(part)
    141 
    142138    result = '│{0}│{1}│{2}│{3}│{4}│{5}│{6}│{7}│'.format(*tuple(args))
    143139    return result
     
    147143    a = sys.argv
    148144    versions = get_versions()
    149     print(versions)
     145    #print('НАЛИЧНИ ВЕРСИИ')
     146    #print(versions)
    150147    if not len(a) == 2 or a[1] not in versions:
    151         print('Give single argument, one of: {} '.format(versions))
    152         print('Will use {}'.format(versions[0]))
     148        print('Дайте максимум един аргумент, възможни стойности: {} '.format(versions))
     149        print('Ще се ползва {}'.format(versions[0]))
    153150        version = versions[0]
    154151    else:
     
    160157    sums = sms['sums']
    161158
    162     print(max_len)
    163     print(sums)
     159    #print(max_len)
     160    #print(sums)
    164161    s = start(max_len)
    165162    d = divider(max_len)
     
    181178    sums = sms['sums']
    182179
    183     print(max_len)
    184     print(sums)
     180    #print(max_len)
     181    #print(sums)
    185182    s = start(max_len)
    186183    d = divider(max_len)
     
    197194    print(e)
    198195
    199 
    200 
    201196   
    202197if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.