Bugzilla – Attachment 101573 Details for
Bug 80387
[EasyHack] extend lint-ui.py to check for UI title labels
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Python script to check title cases
CaseUIFix.py (text/x-python-script), 3.88 KB, created by
Jorendc
on 2014-06-23 11:07:17 UTC
(
hide
)
Description:
Python script to check title cases
Filename:
MIME Type:
Creator:
Jorendc
Created:
2014-06-23 11:07:17 UTC
Size:
3.88 KB
patch
obsolete
>'''Find all UI files -> analyse all labels (either translatable or not) -> check it is a title by checking attributes tag. >Title = every word case >Regular label = sentence case > ><child type="label"> > <object class="GtkLabel" id="label1"> > <property name="visible">True</property> > <property name="can_focus">False</property> > <property name="label" translatable="yes">Save Links Relative to</property> > <attributes> > <attribute name="weight" value="bold"/> > </attributes> > </object> ></child> >''' > >import re >import subprocess >from xml.dom import minidom > >articles = ['a', 'ABCD', 'an', 'and', 'AutoText', 'as', 'at', 'but', 'by', 'CTL', 'down', 'for', 'from', 'in', 'into', 'like', 'near', 'off', 'onto', 'over', 'past', 'upon', 'with', 'when', 'of', 'the', 'to', 'is', '%PRODUCTVERSION', 'ODT', 'ODF', 'ODS', 'ODT', 'ODP', 'HTML', 'SQL', '(SMTP)'] > >def title_except(s): > word_list = re.split(' ', s) > final = [] > for word in word_list: > if (word not in articles): > final.append(word.capitalize()) > else: > final.append(word) > return " ".join(final) > >def parseUI(files): > for UIFile in files: > UIFile = "/Users/Joren/Desktop/LibreOffice/core/" + UIFile.rsplit("./",2)[1] > file = open(UIFile,'r') > #file = open('/Users/Joren/Desktop/LibreOffice/core/basctl/uiconfig/basicide/ui/basicmacrodialog.ui','r') > #parse the xml you got from the file > dom = minidom.parse(file) > file.close() > for label in dom.getElementsByTagName('property'): > for (name, value) in label.attributes.items(): > if value == 'label': > parents = label.parentNode > if parents.getElementsByTagName('attributes'): > #print('Yes!') > value = label.firstChild.nodeValue > changeTo = title_except(value) > if (str(value) != str(changeTo)): > if(value.find("_") != -1 or value.find("%") != -1 or value.find("/") != -1): > print("skipping: " + value) > else: > print(UIFile) > print( str(value) + "\n=> " + str(changeTo) ) > value = value.replace(" ", "\ ") > #print("sed -i '' 's/" + value + "/" + str(title_except(value,articles))+ "/' " + UIFile) > subprocess.call("sed -i '' 's/>" + value + "</>" + str(changeTo)+ "</' " + UIFile, shell=True) > '''file = open(UIFile,'r+') > data = file.read() > data = data.replace(">"+str(value)+"<",">"+str(title_except(value,articles))+"<") > file.write(data) > file.close()''' > > #print(label) > >#filter results in workdir and instdir >def filterFiles(fileList): > filtered = [] > for file in fileList: > found = 0 > splittedFile = file.split("/") > for folder in splittedFile: > if(folder == "instdir" or folder == "workdir"): > found = 1 > break > if (found == 0): > filtered.append(file) > return filtered > > >#Find all .ui files >def findUIFiles(): > try: > filesSearch = subprocess.check_output("cd ~/Desktop/LibreOffice/core && find . -type f -name \"*.ui\"",shell=True).splitlines() > except IOError as e: > # If the file does not exist, then we ignore the step and > # move on. > print("File not found/related") > #except : > # If we don't know what went wrong, we just mention the > # failure. > #print("Sorry, not sure what went wrong here...") > return filesSearch > >result = findUIFiles() >filteredResult = filterFiles (result) >parseUI(filteredResult)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 80387
: 101573