Support creating files in content/
This commit is contained in:
parent
9d73e5eeca
commit
b96ebe211c
1 changed files with 31 additions and 15 deletions
46
add_style.py
46
add_style.py
|
@ -63,24 +63,31 @@ def searchFile(tagmap,name):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def createNewFile(name):
|
def createNewFile(name,folder):
|
||||||
text = "/* Source file https://github.com/MrOtherGuy/firefox-csshacks/tree/master/chrome/{} made available under Mozilla Public License v. 2.0\nSee the above repository for updates as well as full license text. */\n".format(name)
|
filesuffix = "{}/{}".format(folder,name)
|
||||||
|
text = "/* Source file https://github.com/MrOtherGuy/firefox-csshacks/tree/master/{} made available under Mozilla Public License v. 2.0\nSee the above repository for updates as well as full license text. */\n".format(filesuffix)
|
||||||
|
|
||||||
if os.path.isfile("chrome/{}".format(name)):
|
if os.path.isfile(filesuffix):
|
||||||
confirm = input("File {} already exists! proceed (will overwrite) ? [y/N] ".format(name))
|
confirm = input("File {} already exists! proceed (will overwrite) ? [y/N] ".format(filesuffix))
|
||||||
if confirm != "y":
|
if confirm != "y":
|
||||||
print("Aborted")
|
print("Aborted")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
with open("chrome/{}".format(name),"w") as css:
|
with open(filesuffix,"w") as css:
|
||||||
print(text,file=css)
|
print(text,file=css)
|
||||||
print("Created chrome/{}".format(name))
|
print("Created file: {}".format(filesuffix))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def isUpdateOnly(argv):
|
||||||
|
return (argv[1] == "--update-only") or (argv[1] == "-update-only") or (argv[1] == "-u")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) < (2 + (0 if (sys.argv[1] == "--update-only") else 1)):
|
update_only = isUpdateOnly(sys.argv)
|
||||||
|
|
||||||
|
if len(sys.argv) < (2 + (0 if update_only else 1)):
|
||||||
print("usage: add_file.py <filename> <list_of_tags>")
|
print("usage: add_file.py <filename> <list_of_tags>")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
@ -89,20 +96,29 @@ if __name__ == "__main__":
|
||||||
args.append(sys.argv[i])
|
args.append(sys.argv[i])
|
||||||
|
|
||||||
name = sys.argv[1]
|
name = sys.argv[1]
|
||||||
update_only = name == "--update-only"
|
|
||||||
|
|
||||||
file = open("tags.csv")
|
if not(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):
|
||||||
|
createNewFile(name,folder)
|
||||||
|
print("Done")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
tagfile = open("tags.csv")
|
||||||
|
|
||||||
tagmap = file.read().lstrip().splitlines()
|
tagmap = tagfile.read().lstrip().splitlines()
|
||||||
file.close()
|
tagfile.close()
|
||||||
if not(update_only) and searchFile(tagmap,name):
|
if not(update_only) and searchFile(tagmap,name):
|
||||||
print(name + "exist already")
|
print(name + "exist already")
|
||||||
else:
|
else:
|
||||||
if not(update_only):
|
if not(update_only):
|
||||||
exists = createNewFile(name)
|
exists = createNewFile(name,folder)
|
||||||
file = open("tags.csv","a")
|
tagfile = open("tags.csv","a")
|
||||||
file.write(name+","+",".join(args)+"\n")
|
tagfile.write(name+","+",".join(args)+"\n")
|
||||||
file.close()
|
tagfile.close()
|
||||||
else:
|
else:
|
||||||
print("Only update json")
|
print("Only update json")
|
||||||
createJSON(tagmap,name,args,update_only)
|
createJSON(tagmap,name,args,update_only)
|
||||||
|
|
Loading…
Reference in a new issue