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