tools: remove unused code

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2020-05-31 04:28:07 +05:30
parent 58d48ea3ed
commit 236df08388
4 changed files with 0 additions and 225 deletions

View File

@ -1 +0,0 @@
// Run generateOldLayout.js in browser and copy the response here, then run filterTranslations.py to generate translations.

View File

@ -1,92 +0,0 @@
# coding: utf-8
import json
import os
import sys
def loadJson(lfile):
ldata = lfile.read()
cont = ldata.split("var dictionary =")
if len(cont) != 2:
print "Unexpected format for file " + lfile + ". Expected `var dictionary =` from old source code"
exit(1)
trans = cont[1].strip().replace("\n", "")
if trans[-1] == ";":
trans = trans[0: -1]
try:
return json.loads(trans)
except expression as identifier:
print "Something went wrong in parsing old files. Perhaps incorrect formatting?"
exit(1)
def loadTranslations(l10repo):
with open("fieldsFromOldLayout.json") as outfile:
oldLayout = json.load(outfile)
fieldsFromOldLayout = oldLayout["allFields"]
actionsFromOldLayout = oldLayout["actions"]
with open("manualNeededLabels.json") as outfile:
manualNeededLabels = json.load(outfile)
newTranslations = {}
for r, d, f in os.walk(l10repo):
for file in f:
print file
if '.js' in file:
with open(os.path.join(r, file)) as oldfile:
oldTrans = loadJson(oldfile)
print len(oldTrans.keys())
newTrans = {}
for apikey in fieldsFromOldLayout:
currLabel = fieldsFromOldLayout[apikey]["labels"][0] # Just use the first label for now in case multiple labels exist
if currLabel in oldTrans:
newTrans[apikey] = oldTrans[currLabel]
for label in manualNeededLabels:
if label in oldTrans:
newTrans[manualNeededLabels[label]] = oldTrans[label]
else:
newTrans[manualNeededLabels[label]] = manualNeededLabels[label]
for a in actionsFromOldLayout:
actions = actionsFromOldLayout[a]
for action in actions:
if not "label" in action:
continue
curLabel = action["label"]
if curLabel in oldTrans:
newTrans[curLabel] = oldTrans[curLabel]
else:
print "Not found translation for " + curLabel
if "keys" in action:
curKeys = action["keys"]
for key in curKeys:
curLabel = curKeys[key]["label"]
if curLabel in oldTrans:
newTrans[key] = oldTrans[curLabel]
else:
print "Not found translation for " + curLabel
newTranslations[file] = newTrans
for file in newTranslations:
with open("../src/locales/" + file[:-3] + ".json", "w") as newT:
json.dump(newTranslations[file], newT, sort_keys=True, indent=4)
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: fileTranslations.py $CLOUDSTACK_CODE_REPO"
exit(1)
cldstk = sys.argv[1]
l10repo = os.path.join(cldstk, "ui/l10n")
if not os.path.isdir(l10repo):
print "Invalid translations location sent: " + l10repo + " does not exists"
exit(1)
loadTranslations(l10repo)
exit(0)

View File

@ -1,81 +0,0 @@
/* eslint-disable no-mixed-spaces-and-tabs */
// Run this in browser with old UI Running and dump the data to olderLayout.json.
// Then run filterTranslations.py to populate the translations files.
// This is hacky but perhaps more effort isn't needed. Migrate away to the new UI!
var loadLabel = function (allFields, fieldDict, prefix) {
var cols = ''
$.each(Object.keys(fieldDict), function (idx1, fieldId) {
if (fieldDict[fieldId].label) {
if (allFields[fieldId]) {
console.log('[WARN] Found multiple labels for API Key: ' + fieldId)
allFields[fieldId].labels.push(fieldDict[fieldId].label)
allFields[fieldId].components.push(prefix)
} else {
allFields[fieldId] = {
labels: [fieldDict[fieldId].label],
components: [prefix]
}
}
cols = cols + "'" + fieldId + "', "
if (fieldDict[fieldId].columns && $.type(fieldDict[fieldId].columns) === 'object') {
prefix = prefix + '_columns'
var columns = fieldDict[fieldId].columns
$.each(Object.keys(columns), function (idx, colId) {
if (allFields[colId]) {
console.log('[WARN] Found multiple labels for API Key: ' + colId)
allFields[colId].labels.push(columns[colId].label)
allFields[colId].components.push(prefix)
} else {
allFields[colId] = {
labels: [columns[colId].label],
components: [prefix]
}
}
})
}
}
})
return cols
}
var countActions = 0
var loadFields = function (data, prefix) {
if ($.type(data) !== 'object') return {}
var allFields = {}
var columnsOrder = {}
var actions = {}
$.each(Object.keys(data), function (idx, key) {
if (key === 'fields' || key === 'bottomFields' || key === 'topFields') {
var fields = data[key]
var cols = ''
if ($.type(fields) === 'object') {
cols = loadLabel(allFields, fields, prefix)
} else if ($.type(fields) === 'array') {
$.each(fields, function (idx, fieldDict) {
cols = cols + "'" + loadLabel(allFields, fieldDict, prefix) + "', "
})
}
columnsOrder[prefix] = cols.substring(0, cols.length - 2)
} else if (key === 'actions') {
var acVal = data[key]
var curActions = []
$.each(Object.keys(acVal), function (idx, acKey) {
if (acVal[acKey].createForm) {
curActions.push({ action: acKey, label: acVal[acKey].label, keys: acVal[acKey].createForm.fields })
} else {
curActions.push({ action: acKey, label: acVal[acKey].label })
}
})
countActions = countActions + curActions.length
actions[prefix] = curActions
} else if ($.type(data[key]) === 'object' && ($.type(key) !== 'string' || key.indexOf('$') === -1)) {
var recRes = loadFields(data[key], prefix + '.' + key)
$.extend(allFields, recRes.allFields)
$.extend(columnsOrder, recRes.columnsOrder)
$.extend(actions, recRes.actions)
}
})
return { allFields: allFields, columnsOrder: columnsOrder, actions: actions }
}

View File

@ -1,51 +0,0 @@
{
"label.menu.dashboard": "Dashboard",
"label.compute": "Compute",
"label.instances":"Instances",
"label.ssh.key.pairs": "SSH Key Pairs",
"label.affinity.groups": "Affinity Groups",
"label.configuration":"Configuration",
"label.menu.global.settings":"Global Settings",
"label.ldap.configuration":"LDAP Configuration",
"label.hypervisor.capabilities":"Hypervisor Capabilities",
"label.identityandaccess": "Identity and Access",
"label.users":"Users",
"label.menu.accounts":"Accounts",
"label.domains":"Domains",
"label.roles":"Roles",
"label.menu.templates":"Templates",
"label.menu.isos":"ISOs",
"label.monitor": "Monitor",
"label.menu.alerts":"Alerts",
"label.menu.events":"Events",
"label.menu.network":"Network",
"label.public.network":"Public network",
"label.vpc":"VPC",
"label.security.groups":"Security Groups",
"label.public.ips":"Public IP Addresses",
"label.VPN.gateway":"VPN Gateway",
"label.compute.offerings":"Compute Offerings",
"label.menu.disk.offerings":"Disk Offerings",
"label.menu.network.offerings":"Network Offerings",
"label.menu.vpc.offerings":"VPC Offerings",
"label.menu.system.service.offerings":"System Offerings",
"label.plugins":"Plugins",
"label.quota": "Quota",
"label.cloudianstorage": "Cloudian Storage",
"label.projects":"Projects",
"label.storage":"Storage",
"label.volumes":"Volumes",
"label.menu.snapshots":"Snapshots",
"label.vmsnapshot":"VM Snapshots",
"label.menu.infrastructure":"Infrastructure",
"label.zones":"Zones",
"label.pods":"Pods",
"label.clusters":"Clusters",
"label.hosts":"Hosts",
"label.primary.storage":"Primary Storage",
"label.secondary.storage":"Secondary Storage",
"label.system.vms":"System VMs",
"label.virtual.routers":"Virtual Routers",
"label.sockets":"CPU Sockets",
"label.management.servers":"Management Servers"
}