Upload files to 'settings'

This commit is contained in:
Jeison Yehuda Amihud (Blender Dumbass) 2020-12-10 22:06:20 +00:00
parent e6162f6e5d
commit ac4779ad64

View file

@ -92,7 +92,78 @@ def file_open(win, path):
else:
Open(path)
def copy_file(win, from_path, to_path, new_name=""):
############################################################################
# This function exists because coping files is not as simple as reading one
# and writting it to another. Blend-Files for example could have terrible
# amount of linked stuff. And I can't be sure that the user will be always
# using full path mode for these. And even. It's not good to do it anyway.
# because you want to copy the project from one folder to another and keep
# everything pretty much intact.
# So this will make sure that stuff like blend file (maybe if future other
# files) will be copied preserving all the linking inside.
############################################################################
# Let's see if the file is inside the project or full path.
if os.path.exists(win.project+"/"+from_path):
from_path = win.project+"/"+from_path
if os.path.exists(win.project+"/"+to_path):
to_path = win.project+"/"+to_path
# Now let's make sure that unless specified we are not overwritting some
# existing file.
if not new_name:
new_name = from_path[from_path.rfind("/")+1:]
count = 0
while new_name in os.listdir(to_path):
count = count + 1
new_name = from_path[from_path.rfind("/")+1:from_path.rfind(".")]+"_"+str(count)+from_path[from_path.rfind("."):]
# Now let's combine name and name
to_path = to_path + "/" + new_name
still = True
# Let's check that we got a blend file
blendfile = False
for bt in [".blend", ".blend1"]:
if from_path.endswith(bt):
blendfile = True
if blendfile:
# Now before we copy blend file we need to check whether Blender is even
# installed.
noblender = os.system(get_current_blender()+" -v") # It's a simple version check.
# If there is no Blender installed os.system will return a value higher then 0.
if not noblender:
still = False
# Now what we are going to do is start blender using a little expression
# to force it to save file as.
os.system(get_current_blender()\
+" -b "\
+from_path.replace(" ", "\ ")\
+" --python-expr import\ bpy\;\ bpy.ops.wm.save_as_mainfile\(filepath=\\\""\
+to_path.replace(" ", "\ ")+"\\\"\)")
if still:
# If it's not a blendfile we going to use this.
with open(from_path, "rb") as in_file, open(to_path, "wb") as out_file:
out_file.write(in_file.read())
return to_path
def get_current_blender():