From a0b3021bdcf76859054fda8e30abb3ed47749e83 Mon Sep 17 00:00:00 2001 From: Bennett Goble Date: Wed, 29 May 2024 08:10:00 -0700 Subject: Trim trailing whitespace Start trimming trailing whitespace, but limit the blast radius to a handful of file types. --- scripts/code_tools/fix_xml_indentations.py | 2 +- scripts/code_tools/modified-strings.sh | 14 +++++++------- scripts/code_tools/modified_strings.py | 16 ++++++++-------- scripts/content_tools/anim_tool.py | 26 +++++++++++++------------- scripts/content_tools/arche_tool.py | 6 +++--- scripts/content_tools/dae_tool.py | 10 +++++----- scripts/content_tools/skel_tool.py | 26 +++++++++++++------------- scripts/metrics/viewer_asset_logs.py | 8 ++++---- scripts/metrics/viewerstats.py | 16 ++++++++-------- scripts/template_verifier.py | 10 +++++----- scripts/templates/template-cpp.cpp | 2 +- scripts/templates/template-h.h | 2 +- 12 files changed, 69 insertions(+), 69 deletions(-) (limited to 'scripts') diff --git a/scripts/code_tools/fix_xml_indentations.py b/scripts/code_tools/fix_xml_indentations.py index 9c8a1fc04b..e317e4f7f6 100644 --- a/scripts/code_tools/fix_xml_indentations.py +++ b/scripts/code_tools/fix_xml_indentations.py @@ -72,7 +72,7 @@ def save_xml(tree, file_path, xml_decl, indent_text=False, indent_tab=False, rm_ if rm_space: xml_string = xml_string.replace(' />', '/>') - xml_decl = (xml_decl if (xml_decl and not rewrite_decl) + xml_decl = (xml_decl if (xml_decl and not rewrite_decl) else '') try: diff --git a/scripts/code_tools/modified-strings.sh b/scripts/code_tools/modified-strings.sh index 435dda3f5d..932b0a4bfc 100644 --- a/scripts/code_tools/modified-strings.sh +++ b/scripts/code_tools/modified-strings.sh @@ -38,11 +38,11 @@ do -h|--help) Action=USAGE ;; - + -v|--verbose) Verbose=true ;; - + ## ## Select the revision to compare against ## @@ -79,7 +79,7 @@ do break fi ;; - esac + esac shift # always consume 1 done @@ -107,10 +107,10 @@ then cat <] [] - where + where --verbose shows progress messages on stderr (the command takes a while, so this is reassuring) -r specifies a git revision (branch, tag, commit, or relative specifier) @@ -124,9 +124,9 @@ Usage: the path of a file that has a string change (columns 2 and 3 are empty for lines with a filename) name the name attribute of a string or label whose value changed - English value + English value the current value of the string or label whose value changed - for strings, newlines are changed to '\n' and tab characters are changed to '\t' + for strings, newlines are changed to '\n' and tab characters are changed to '\t' There is also a column for each of the language directories following the English. diff --git a/scripts/code_tools/modified_strings.py b/scripts/code_tools/modified_strings.py index 20ed1b0555..c777fc8c0d 100644 --- a/scripts/code_tools/modified_strings.py +++ b/scripts/code_tools/modified_strings.py @@ -49,7 +49,7 @@ into google sheets. If the --rev revision already contains a translation for the text, it will be included in the spreadsheet for reference. - + Normally you would want --rev_base to be the last revision to have translations added, and --rev to be the tip of the current project. You can find the last commit with translation work using "git log --grep INTL- | head" @@ -242,7 +242,7 @@ def find_deletions(mod_tree, base_tree, lang, args, f): mod_filename = transl_filename.replace("/xui/{}/".format(lang), "/xui/{}/".format(args.base_lang)) #print("checking",transl_filename,"against",mod_filename) try: - mod_blob = mod_tree[mod_filename] + mod_blob = mod_tree[mod_filename] except: print(" delete file", transl_filename, file=f) continue @@ -257,7 +257,7 @@ def find_deletions(mod_tree, base_tree, lang, args, f): if not elt_key in mod_dict: if lines == 0: print(" in file", transl_filename, file=f) - lines += 1 + lines += 1 print(" delete element", elt_key, file=f) else: transl_elt = transl_dict[elt_key] @@ -266,14 +266,14 @@ def find_deletions(mod_tree, base_tree, lang, args, f): if not a in mod_elt.attrib: if lines == 0: print(" in file", transl_filename, file=f) - lines += 1 + lines += 1 print(" delete attribute", a, "from", elt_key, file=f) if transl_elt.text and (not mod_elt.text): if lines == 0: print(" in file", transl_filename, file=f) - lines += 1 + lines += 1 print(" delete text from", elt_key, file=f) - + def save_translation_file(per_lang_data, aux_data, outfile): langs = sorted(per_lang_data.keys()) @@ -310,12 +310,12 @@ def save_translation_file(per_lang_data, aux_data, outfile): # Reference info, not for translation for aux, data in list(aux_data.items()): - df = pd.DataFrame(data, columns = ["Key", "Value"]) + df = pd.DataFrame(data, columns = ["Key", "Value"]) df.to_excel(writer, index=False, sheet_name=aux) worksheet = writer.sheets[aux] worksheet.set_column('A:A', 50, bold_wrap_format) worksheet.set_column('B:B', 80, wrap_format) - + print("Writing", outfile) writer.save() diff --git a/scripts/content_tools/anim_tool.py b/scripts/content_tools/anim_tool.py index 4a0773951e..07159a8052 100644 --- a/scripts/content_tools/anim_tool.py +++ b/scripts/content_tools/anim_tool.py @@ -92,7 +92,7 @@ class FilePacker(object): # Now pad what's left of str out to 'size' with nul bytes. buf = str + ("\000" * (size-len(str))) self.buffer.write(buf) - + class FileUnpacker(object): def __init__(self, filename): with open(filename,"rb") as f: @@ -103,7 +103,7 @@ class FileUnpacker(object): result = struct.unpack_from(fmt, self.buffer, self.offset) self.offset += struct.calcsize(fmt) return result - + def unpack_string(self, size=0): # Nonzero size means we must consider exactly the next 'size' # characters in self.buffer. @@ -131,7 +131,7 @@ def F32_to_U16(val, lower, upper): # make sure that the value is positive and normalized to <0, 1> val -= lower; val /= (upper - lower); - + # return the U16 return int(math.floor(val*U16MAX)) @@ -149,7 +149,7 @@ def U16_to_F32(ival, lower, upper): # make sure that zeroes come through as zero if abs(val) < max_error: val = 0.0 - return val; + return val; class RotKey(object): def __init__(self, time, duration, rot): @@ -185,7 +185,7 @@ class RotKey(object): fp.pack("1: @@ -117,7 +117,7 @@ def list_skel_tree(tree): for element in tree.getroot().iter(): if element.tag == "bone": print(element.get("name"),"-",element.get("support")) - + def validate_child_order(tree, ogtree, fix=False): unfixable = 0 @@ -182,7 +182,7 @@ def validate_skel_tree(tree, ogtree, reftree, fix=False): print("validate_skel_tree") (num_bones,num_cvs) = (0,0) unfixable = 0 - defaults = {"connected": "false", + defaults = {"connected": "false", "group": "Face" } for element in tree.getroot().iter(): @@ -232,7 +232,7 @@ def validate_skel_tree(tree, ogtree, reftree, fix=False): if element.get("support")=="extended": if element.get("pos") != element.get("pivot"): print("extended joint",element.get("name"),"has mismatched pos, pivot") - + if element.tag == "linden_skeleton": num_bones = int(element.get("num_bones")) @@ -253,7 +253,7 @@ def validate_skel_tree(tree, ogtree, reftree, fix=False): if fix and (unfixable > 0): print("BAD FILE:", unfixable,"errs could not be fixed") - + def slider_info(ladtree,skeltree): for param in ladtree.iter("param"): @@ -287,7 +287,7 @@ def slider_info(ladtree,skeltree): print(" Offset MaxX", offset_max[0]) print(" Offset MaxY", offset_max[1]) print(" Offset MaxZ", offset_max[2]) - + # Check contents of avatar_lad file relative to a specified skeleton def validate_lad_tree(ladtree,skeltree,orig_ladtree): print("validate_lad_tree") @@ -344,7 +344,7 @@ def validate_lad_tree(ladtree,skeltree,orig_ladtree): expected_offset = tuple([bone_offset[0],-bone_offset[1],bone_offset[2]]) if left_offset != expected_offset: print("offset mismatch between",bone_name,"and",left_name,"in param",param.get("id","-1")) - + drivers = {} for driven_param in ladtree.iter("driven"): driver = driven_param.getparent().getparent() @@ -380,7 +380,7 @@ def validate_lad_tree(ladtree,skeltree,orig_ladtree): print("removed",set(orig_message_ids) - set(message_ids)) else: print("message ids OK") - + def remove_joint_by_name(tree, name): print("remove joint:",name) elt = get_element_by_name(tree,name) @@ -395,7 +395,7 @@ def remove_joint_by_name(tree, name): elt[:] = [] print("parent now:",[e.get("name") for e in list(parent)]) elt = get_element_by_name(tree,name) - + def compare_skel_trees(atree,btree): diffs = {} realdiffs = {} @@ -513,7 +513,7 @@ if __name__ == "__main__": if ladtree and tree and args.slider_info: slider_info(ladtree,tree) - + if args.outfilename: f = open(args.outfilename,"w") print(etree.tostring(tree, pretty_print=True), file=f) #need update to get: , short_empty_elements=True) diff --git a/scripts/metrics/viewer_asset_logs.py b/scripts/metrics/viewer_asset_logs.py index bd996dff79..4fb9fd15b3 100644 --- a/scripts/metrics/viewer_asset_logs.py +++ b/scripts/metrics/viewer_asset_logs.py @@ -63,7 +63,7 @@ def update_stats(stats,rec): # handle fps record as special case pass else: - #print "field",field + #print "field",field stats.setdefault(field,{}) type_stats = stats.get(field) newcount = val["resp_count"] @@ -75,9 +75,9 @@ def update_stats(stats,rec): type_stats["sum_bytes"] = type_stats.get("sum_bytes",0) + val["resp_count"] * val.get("resp_mean_bytes",0) type_stats["enqueued"] = type_stats.get("enqueued",0) + val["enqueued"] type_stats["dequeued"] = type_stats.get("dequeued",0) + val["dequeued"] - - - + + + if __name__ == "__main__": parser = argparse.ArgumentParser(description="process metric xml files for viewer asset fetching") diff --git a/scripts/metrics/viewerstats.py b/scripts/metrics/viewerstats.py index e64343329c..41bc493aaa 100755 --- a/scripts/metrics/viewerstats.py +++ b/scripts/metrics/viewerstats.py @@ -144,7 +144,7 @@ def get_used_strings(root_dir): #if ext not in [".cpp", ".hpp", ".h", ".xml"]: # skipped_ext.add(ext) # continue - + full_name = os.path.join(dir_name,fname) with open(full_name,"r") as f: @@ -158,8 +158,8 @@ def get_used_strings(root_dir): print("skipped extensions", skipped_ext) print("got used_str", len(used_str)) return used_str - - + + if __name__ == "__main__": parser = argparse.ArgumentParser(description="process tab-separated table containing viewerstats logs") @@ -184,7 +184,7 @@ if __name__ == "__main__": if args.preferences: print("\nSETTINGS.XML") settings_sd = parse_settings_xml("settings.xml") - #for skey,svals in settings_sd.items(): + #for skey,svals in settings_sd.items(): # print skey, "=>", svals (all_str,_,_,_) = show_stats_by_key(recs,["preferences","settings"],settings_sd) print() @@ -211,16 +211,16 @@ if __name__ == "__main__": print("PREFIX_USED", len(prefix_used), ",".join(list(prefix_used))) print() unref_strings = unref_strings - prefix_used - + print("\nUNREF_IN_CODE " + str(len(unref_strings)) + "\n") print("\n".join(list(unref_strings))) settings_str = read_raw_settings_xml("settings.xml") # Do this via direct string munging to generate minimal changeset settings_edited = remove_settings(settings_str,unref_strings) write_raw_settings_xml("settings.xml.edit",settings_edited) - - - + + + diff --git a/scripts/template_verifier.py b/scripts/template_verifier.py index ee8492db5e..65850f7a28 100755 --- a/scripts/template_verifier.py +++ b/scripts/template_verifier.py @@ -73,8 +73,8 @@ from indra.ipc import tokenstream from indra.ipc import llmessage def getstatusall(command): - """ Like commands.getstatusoutput, but returns stdout and - stderr separately(to get around "killed by signal 15" getting + """ Like commands.getstatusoutput, but returns stdout and + stderr separately(to get around "killed by signal 15" getting included as part of the file). Also, works on Windows.""" (input, out, err) = os.popen3(command, 't') status = input.close() # send no input to the command @@ -257,7 +257,7 @@ http://wiki.secondlife.com/wiki/Template_verifier.py elif len(args) == 1: master_url = None current_filename = args[0] - print("master:", options.master_url) + print("master:", options.master_url) print("current:", current_filename) current_url = 'file://%s' % current_filename # nothing specified, use defaults for everything @@ -269,7 +269,7 @@ http://wiki.secondlife.com/wiki/Template_verifier.py if master_url is None: master_url = options.master_url - + if current_url is None: current_filename = local_template_filename() print("master:", options.master_url) @@ -307,7 +307,7 @@ http://wiki.secondlife.com/wiki/Template_verifier.py print("Syntax-checking the local template ONLY, no compatibility check is being run.") print("Cause: %s\n\n" % e) return 0 - + acceptable, compat = compare( master_parsed, current_parsed, options.mode) diff --git a/scripts/templates/template-cpp.cpp b/scripts/templates/template-cpp.cpp index 35d8441c87..8ee04942bf 100755 --- a/scripts/templates/template-cpp.cpp +++ b/scripts/templates/template-cpp.cpp @@ -1,4 +1,4 @@ -/** +/** * @file #filename#.cpp * @brief Implementation of #filename# * @author #getpass.getuser()#@lindenlab.com diff --git a/scripts/templates/template-h.h b/scripts/templates/template-h.h index ce7b4ddc87..d7677c256b 100755 --- a/scripts/templates/template-h.h +++ b/scripts/templates/template-h.h @@ -1,4 +1,4 @@ -/** +/** * @file #filename#.h * @brief Header file for #filename# * @author #getpass.getuser()#@lindenlab.com -- cgit v1.2.3 From 34dfd7d5996b1b6117c2155bb95aeb377038bb6e Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Mon, 10 Jun 2024 17:05:19 +0300 Subject: Update fix_whitespace.py to handle newlines correctly --- scripts/code_tools/fix_whitespace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/code_tools/fix_whitespace.py b/scripts/code_tools/fix_whitespace.py index 91e82f26f4..7a88265479 100644 --- a/scripts/code_tools/fix_whitespace.py +++ b/scripts/code_tools/fix_whitespace.py @@ -55,7 +55,7 @@ def convert_tabs_to_spaces(file_path, tab_stop): new_lines.append(new_line + '\n') - with open(file_path, 'w') as file: + with open(file_path, 'w', newline='\n') as file: file.writelines(new_lines) def process_directory(directory, extensions, tab_stop): -- cgit v1.2.3