Add size to update info
This commit is contained in:
parent
7e73804348
commit
0ef82187d6
@ -5,7 +5,7 @@ import re
|
|||||||
|
|
||||||
|
|
||||||
def parse_language_names():
|
def parse_language_names():
|
||||||
root = os.path.abspath(os.path.basename(__file__) + '/..')
|
root = os.path.abspath(os.path.basename(__file__) + '/../../..')
|
||||||
lines = []
|
lines = []
|
||||||
with open(root + '/src/languagecodes.cpp', 'r') as f:
|
with open(root + '/src/languagecodes.cpp', 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
@ -31,12 +31,12 @@ if len(sys.argv) > 2:
|
|||||||
language_names = parse_language_names()
|
language_names = parse_language_names()
|
||||||
|
|
||||||
files = {}
|
files = {}
|
||||||
with os.scandir(tessdata_dir) as it:
|
it = os.scandir(tessdata_dir)
|
||||||
for f in it:
|
for f in it:
|
||||||
if not f.is_file() or f.name in ["LICENSE", "README.md"]:
|
if not f.is_file() or f.name in ["LICENSE", "README.md"]:
|
||||||
continue
|
continue
|
||||||
name = f.name[:f.name.index('.')]
|
name = f.name[:f.name.index('.')]
|
||||||
files.setdefault(name, []).append(f.name)
|
files.setdefault(name, []).append(f.name)
|
||||||
|
|
||||||
print(',"recognizers": {')
|
print(',"recognizers": {')
|
||||||
comma = ''
|
comma = ''
|
||||||
@ -52,8 +52,9 @@ for name, file_names in files.items():
|
|||||||
git_cmd = ['git', 'log', '-1', '--pretty=format:%cI', file_name]
|
git_cmd = ['git', 'log', '-1', '--pretty=format:%cI', file_name]
|
||||||
date = subprocess.run(git_cmd, cwd=tessdata_dir, universal_newlines=True,
|
date = subprocess.run(git_cmd, cwd=tessdata_dir, universal_newlines=True,
|
||||||
stdout=subprocess.PIPE, check=True).stdout
|
stdout=subprocess.PIPE, check=True).stdout
|
||||||
print(' {{"url":"{}/{}", "path":"$tessdata$/{}", "date":"{}"}}'.format(
|
size = os.path.getsize(os.path.join(tessdata_dir, file_name))
|
||||||
download_url, file_name, file_name, date))
|
print(' {{"url":"{}/{}", "path":"$tessdata$/{}", "date":"{}", "size":{}}}'.format(
|
||||||
|
download_url, file_name, file_name, date, size))
|
||||||
print(' ]}')
|
print(' ]}')
|
||||||
print('}')
|
print('}')
|
||||||
|
|
||||||
|
@ -8,16 +8,16 @@ if len(sys.argv) > 1:
|
|||||||
download_url = sys.argv[1]
|
download_url = sys.argv[1]
|
||||||
|
|
||||||
subdir = 'translators'
|
subdir = 'translators'
|
||||||
root = os.path.abspath(os.path.basename(__file__) + '/..')
|
root = os.path.abspath(os.path.basename(__file__) + '/../../..')
|
||||||
translators_dir = root + '/' + subdir
|
translators_dir = root + '/' + subdir
|
||||||
|
|
||||||
files = {}
|
files = {}
|
||||||
with os.scandir(translators_dir) as it:
|
it = os.scandir(translators_dir)
|
||||||
for f in it:
|
for f in it:
|
||||||
if not f.is_file() or not f.name.endswith('.js'):
|
if not f.is_file() or not f.name.endswith('.js'):
|
||||||
continue
|
continue
|
||||||
name = f.name[:f.name.index('.')]
|
name = f.name[:f.name.index('.')]
|
||||||
files[name] = f.name
|
files[name] = f.name
|
||||||
|
|
||||||
print(',"translators":{')
|
print(',"translators":{')
|
||||||
comma = ''
|
comma = ''
|
||||||
@ -25,9 +25,13 @@ for name, file_name in files.items():
|
|||||||
print(' {}"{}": {{"files":['.format(comma, name))
|
print(' {}"{}": {{"files":['.format(comma, name))
|
||||||
comma = ','
|
comma = ','
|
||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
|
size = 0
|
||||||
with open(os.path.join(translators_dir, file_name), 'rb') as f:
|
with open(os.path.join(translators_dir, file_name), 'rb') as f:
|
||||||
md5.update(f.read())
|
data = f.read()
|
||||||
print(' {{"url":"{}/{}", "path":"$translators$/{}", "md5":"{}"}}'.format(
|
size = len(data)
|
||||||
download_url, subdir + '/' + file_name, file_name, md5.hexdigest()))
|
md5.update(data)
|
||||||
|
print(' {{"url":"{}/{}", "path":"$translators$/{}", "md5":"{}", "size":{}}}'.format(
|
||||||
|
download_url, subdir + '/' + file_name, file_name,
|
||||||
|
md5.hexdigest(), size))
|
||||||
print(' ]}')
|
print(' ]}')
|
||||||
print('}')
|
print('}')
|
||||||
|
@ -20,6 +20,35 @@ namespace
|
|||||||
const auto versionKey = "version";
|
const auto versionKey = "version";
|
||||||
const auto filesKey = "files";
|
const auto filesKey = "files";
|
||||||
|
|
||||||
|
QString sizeString(qint64 bytes, int precision)
|
||||||
|
{
|
||||||
|
if (bytes < 1)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
const auto kb = 1024.0;
|
||||||
|
const auto mb = 1024 * kb;
|
||||||
|
const auto gb = 1024 * mb;
|
||||||
|
const auto tb = 1024 * gb;
|
||||||
|
|
||||||
|
if (bytes >= tb) {
|
||||||
|
return QString::number(bytes / tb, 'f', precision) + ' ' +
|
||||||
|
QObject::tr("Tb");
|
||||||
|
}
|
||||||
|
if (bytes >= gb) {
|
||||||
|
return QString::number(bytes / gb, 'f', precision) + ' ' +
|
||||||
|
QObject::tr("Gb");
|
||||||
|
}
|
||||||
|
if (bytes >= mb) {
|
||||||
|
return QString::number(bytes / mb, 'f', precision) + ' ' +
|
||||||
|
QObject::tr("Mb");
|
||||||
|
}
|
||||||
|
if (bytes >= kb) {
|
||||||
|
return QString::number(bytes / kb, 'f', precision) + ' ' +
|
||||||
|
QObject::tr("Kb");
|
||||||
|
}
|
||||||
|
return QString::number(bytes) + ' ' + QObject::tr("bytes");
|
||||||
|
}
|
||||||
|
|
||||||
QString toString(State state)
|
QString toString(State state)
|
||||||
{
|
{
|
||||||
const QMap<State, QString> names{
|
const QMap<State, QString> names{
|
||||||
@ -324,6 +353,8 @@ std::unique_ptr<Model::Component> Model::parse(const QJsonObject &json) const
|
|||||||
file.md5 = object["md5"].toString();
|
file.md5 = object["md5"].toString();
|
||||||
file.versionDate =
|
file.versionDate =
|
||||||
QDateTime::fromString(object["date"].toString(), Qt::ISODate);
|
QDateTime::fromString(object["date"].toString(), Qt::ISODate);
|
||||||
|
const auto size = object["size"].toInt();
|
||||||
|
result->size += size;
|
||||||
result->files.push_back(file);
|
result->files.push_back(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,9 +616,10 @@ QVariant Model::headerData(int section, Qt::Orientation orientation,
|
|||||||
return section + 1;
|
return section + 1;
|
||||||
|
|
||||||
const QMap<Column, QString> names{
|
const QMap<Column, QString> names{
|
||||||
{Column::Name, tr("Name")}, {Column::State, tr("State")},
|
{Column::Name, tr("Name")}, {Column::State, tr("State")},
|
||||||
{Column::Action, tr("Action")}, {Column::Version, tr("Version")},
|
{Column::Action, tr("Action")}, {Column::Size, tr("Size")},
|
||||||
{Column::Progress, tr("Progress")}, {Column::Files, tr("Files")},
|
{Column::Version, tr("Version")}, {Column::Progress, tr("Progress")},
|
||||||
|
{Column::Files, tr("Files")},
|
||||||
};
|
};
|
||||||
return names.value(Column(section));
|
return names.value(Column(section));
|
||||||
}
|
}
|
||||||
@ -604,6 +636,7 @@ QVariant Model::data(const QModelIndex &index, int role) const
|
|||||||
case int(Column::Name): return QObject::tr(qPrintable(ptr->name));
|
case int(Column::Name): return QObject::tr(qPrintable(ptr->name));
|
||||||
case int(Column::State): return toString(ptr->state);
|
case int(Column::State): return toString(ptr->state);
|
||||||
case int(Column::Action): return toString(ptr->action);
|
case int(Column::Action): return toString(ptr->action);
|
||||||
|
case int(Column::Size): return sizeString(ptr->size, 1);
|
||||||
case int(Column::Version): return ptr->version;
|
case int(Column::Version): return ptr->version;
|
||||||
case int(Column::Progress):
|
case int(Column::Progress):
|
||||||
return ptr->progress > 0 ? ptr->progress : QVariant();
|
return ptr->progress > 0 ? ptr->progress : QVariant();
|
||||||
|
@ -42,7 +42,16 @@ class Model : public QAbstractItemModel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum class Column { Name, State, Action, Version, Progress, Files, Count };
|
enum class Column {
|
||||||
|
Name,
|
||||||
|
State,
|
||||||
|
Action,
|
||||||
|
Size,
|
||||||
|
Version,
|
||||||
|
Progress,
|
||||||
|
Files,
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
explicit Model(QObject* parent = nullptr);
|
explicit Model(QObject* parent = nullptr);
|
||||||
|
|
||||||
@ -78,6 +87,7 @@ private:
|
|||||||
Component* parent{nullptr};
|
Component* parent{nullptr};
|
||||||
int index{-1};
|
int index{-1};
|
||||||
int progress{0};
|
int progress{0};
|
||||||
|
int size{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Component> parse(const QJsonObject& json) const;
|
std::unique_ptr<Component> parse(const QJsonObject& json) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user