mirror of
https://codeberg.org/claui/mobile-config-firefox.git
synced 2024-11-09 19:30:15 +00:00
add a parameter to list existing tags
This patch adds support for "-l" or "--list" or "-list" parameters to read and list unique tags from tags.csv
This commit is contained in:
parent
f0caa6d5ae
commit
ef7a9c73f7
1 changed files with 55 additions and 16 deletions
71
add_style.py
71
add_style.py
|
@ -3,14 +3,22 @@
|
|||
#
|
||||
# usage:
|
||||
# add_style.py <file_name> <tags>
|
||||
# where <tags> is a space-separated list of tags to apply for that style (1 minimum)
|
||||
#
|
||||
# where <tags> is a space-separated list of tags to apply
|
||||
# for that style (1 minimum). Creates a new file to
|
||||
# chrome/ folder and updates tags.csv and docs/tagmap.json
|
||||
#
|
||||
# OR
|
||||
# add_style-py --update-only
|
||||
#
|
||||
# When called with <file_name> <tags> it will create a new file to chrome/ folder and
|
||||
# update tags.csv and docs/tagmap.json
|
||||
# add_style.py --update-only
|
||||
#
|
||||
# With --update-only it will only update docs/tagmap.json based on tags.csv
|
||||
# updates docs/tagmap.json based on tags.csv without creating anything
|
||||
#
|
||||
# OR
|
||||
#
|
||||
# add_style.py --list
|
||||
#
|
||||
# shows a list of unique tags used in tags.csv
|
||||
|
||||
import sys, os
|
||||
|
||||
|
@ -79,15 +87,40 @@ def createNewFile(name,folder):
|
|||
print("Created file: {}".format(filesuffix))
|
||||
return True
|
||||
|
||||
def isUpdateOnly(argv):
|
||||
return (argv[1] == "--update-only") or (argv[1] == "-update-only") or (argv[1] == "-u")
|
||||
|
||||
class TaskMode:
|
||||
def __init__(self,args):
|
||||
self.show_help = len(args) < 2 or (args[1] == "-h")
|
||||
if self.show_help:
|
||||
self.update_only = False
|
||||
self.list_tags = False
|
||||
self.normal = False
|
||||
else:
|
||||
self.update_only = (args[1] == "--update-only") or (args[1] == "-update-only") or (args[1] == "-u")
|
||||
self.list_tags = (args[1] == "--list") or (args[1] == "-list") or (args[1] == "-l")
|
||||
self.normal = not self.update_only and (not self.list_tags)
|
||||
self.min_arg_length = (3 if self.normal else 2)
|
||||
|
||||
def printCurrentTags(filecontent):
|
||||
tags = [];
|
||||
for line in filecontent:
|
||||
tokens = line.rsplit(",")
|
||||
filterEmpty(tokens)
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
for t in range(1,len(tokens)):
|
||||
if tags.count(tokens[t]) == 0:
|
||||
tags.append(tokens[t])
|
||||
tags.sort()
|
||||
print("\n".join(tags))
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
update_only = isUpdateOnly(sys.argv)
|
||||
runmode = TaskMode(sys.argv)
|
||||
|
||||
if len(sys.argv) < (2 + (0 if update_only else 1)):
|
||||
if runmode.show_help or len(sys.argv) < runmode.min_arg_length:
|
||||
print("usage: add_file.py <filename> <list_of_tags>")
|
||||
exit()
|
||||
|
||||
|
@ -97,12 +130,12 @@ if __name__ == "__main__":
|
|||
|
||||
name = sys.argv[1]
|
||||
|
||||
if not(update_only) and not(name.endswith(".css")):
|
||||
if not(runmode.update_only) and not(name.endswith(".css")):
|
||||
name += ".css"
|
||||
# For the moment files in content/ are not tagged, but the script can still create the css files
|
||||
folder = "content" if ("-content" in sys.argv) else "chrome"
|
||||
|
||||
if(folder == "content") and not(update_only):
|
||||
if(folder == "content") and not(runmode.update_only):
|
||||
createNewFile(name,folder)
|
||||
print("Done")
|
||||
exit(0)
|
||||
|
@ -111,16 +144,22 @@ if __name__ == "__main__":
|
|||
|
||||
tagmap = tagfile.read().lstrip().splitlines()
|
||||
tagfile.close()
|
||||
if not(update_only) and searchFile(tagmap,name):
|
||||
if runmode.normal and searchFile(tagmap,name):
|
||||
print(name + "exist already")
|
||||
else:
|
||||
if not(update_only):
|
||||
if runmode.normal:
|
||||
exists = createNewFile(name,folder)
|
||||
tagfile = open("tags.csv","a")
|
||||
tagfile.write(name+","+",".join(args)+"\n")
|
||||
tagfile.close()
|
||||
else:
|
||||
createJSON(tagmap,name,args,runmode.update_only)
|
||||
elif runmode.update_only:
|
||||
print("Only update json")
|
||||
createJSON(tagmap,name,args,update_only)
|
||||
print("Done")
|
||||
createJSON(tagmap,name,args,runmode.update_only)
|
||||
elif runmode.list_tags:
|
||||
print("listing tags...")
|
||||
printCurrentTags(tagmap)
|
||||
else:
|
||||
print("this shouldn't happen!")
|
||||
# print("Done")
|
||||
exit(0)
|
||||
|
|
Loading…
Reference in a new issue