def post(self): uploads = self.get_uploads() for file in uploads: filename = blobstore.BlobInfo(file.key()).filename user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() currDirObj = my_user.currDir.get() path = '' if functions.isRootDirectory(my_user): path = currDirObj.dirPath + filename else: path = currDirObj.dirPath + '/' + filename file_id = my_user.key.id() + path file_key = ndb.Key(File, file_id) logging.info(file_id) if functions.exists(file_key, currDirObj.files): file_object = File(id=file_id) file_object.fileName = filename file_object.data = file.key() file_object.put() currDirObj.files.append(file_key) currDirObj.put() else: # Delete uploaded file from the blobstore blobstore.delete(file.key()) logging.debug("File with the same name already exists!") self.redirect('/')
def post(self): self.response.headers['Content-Type'] = 'text/html' button = self.request.get('button') if button == 'Add': directory_name = self.request.get('value') directory_name = re.sub(r'[/;]', '', directory_name).lstrip() if not (directory_name is None or directory_name == ''): user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() logging.info("my user key in post method") logging.info(my_user) parent_dir_obj = my_user.currDir.get() path = '' if functions.isRootDirectory(my_user): path = parent_dir_obj.dirPath + directory_name else: path = parent_dir_obj.dirPath + '/' + directory_name directory_id = my_user.key.id() + path directory = Directory(id=directory_id) logging.info("dir ID") logging.info(directory_id) logging.info(parent_dir_obj.subDir) # If directory already exists if functions.exists(directory.key, parent_dir_obj.subDir): parent_dir_obj.subDir.append(directory.key) parent_dir_obj.put() logging.info("parent_dir_obj") logging.info(parent_dir_obj) # Saving all params of dir to db directory.parentDirectory = my_user.currDir directory.dirName = directory_name directory.dirPath = path directory.put() self.redirect('/') elif button == 'Delete': name = self.request.get('name') type = self.request.get('fType') if type == 'file': user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() parent_dir_obj = my_user.currDir.get() path = '' if functions.isRootDirectory(my_user): path = parent_dir_obj.dirPath + name else: path = parent_dir_obj.dirPath + '/' + name file_id = my_user.key.id() + path file_key = ndb.Key(File, file_id) parent_dir_obj.files.remove(file_key) parent_dir_obj.put() blobObject = file_key.get().data blobstore.delete(blobObject) file_key.delete() elif type == 'directory': user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() parent_dir_obj = my_user.currDir.get() path = '' if functions.isRootDirectory(my_user): path = parent_dir_obj.dirPath + name else: path = parent_dir_obj.dirPath + '/' + name directory_id = my_user.key.id() + path directory_key = ndb.Key(Directory, directory_id) directory_object = directory_key.get() if not directory_object.files and not directory_object.subDir: #Delete all the references parent_dir_obj.subDir.remove(directory_key) parent_dir_obj.put() # Delete directory from datastore directory_key.delete() self.redirect('/') elif button == 'Up': user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() if not functions.isRootDirectory(my_user): parent_dir_obj = my_user.currDir.get().parentDirectory my_user.currDir = parent_dir_obj my_user.put() self.redirect('/') elif button == 'Home': user = users.get_current_user() my_user_key = ndb.Key(MyUser, user.user_id()) my_user = my_user_key.get() my_user.currDir = ndb.Key(Directory, my_user.key.id() + '/') my_user.put() self.redirect('/')
def model_generation(): input=open("models_char.txt","r") output=open("humans.txt","w") output2=open("objects.txt","w") output3=open("environments.txt","w") lines=input.readlines() check=False for temp in lines: line=temp.split() human,color,scale=functions.human_path(line[0],line[1],line[2]) if human!=None: if(color=='none'): color='NA' else: color=colors.to_rgba(color) color = '_'.join(str(e) for e in color) scale3=1 if(line[3]==0): scale3=0.9 elif line[3]==2: scale3=1.2 scale=str(scale*5)+'_'+str(scale3*scale*5)+'_'+str(scale*5) output.write(human+' '+color+' '+scale+' '+str(line[4])+' 0 1\n') else : if functions.exists(line[0],True): size=1 print(line[2]) if (line[2]==2): size=size*1.5 elif line[2]==0: size = size * .75 if line[1]=='none': color='NA' else: color=colors.to_rgba(line[1]) color='_'.join(str(e) for e in color) size2=size3=size if line[0]=='chair' and size2==1.5: size=1 size3=1 size2=1.2 output2.write(line[0]+' '+color+' '+str(size2)+'_'+str(size)+'_'+str(+size3)+' '+str(line[3])+' '+str(functions.inv_math[functions.models.index(line[0])])+' '+ str(functions.e[functions.models.index(line[0])])+'\n') elif functions.exists(line[0],False): check=True output3.write(str(line[0])+' '+str(line[3])+' 0 1') else : size = 1 print(line[2]) if (line[2] == 2): size = size * 1.15 elif line[2] == 0: size = size * .75 if line[1] == 'none': color = 'NA' else: color = colors.to_rgba(line[1]) color = '_'.join(str(e) for e in color) output2.write('box' + ' ' + color + ' ' + str(size) + str(line[3]) + ' 0.1 0.1\n') if check ==False: output3.write('Room 0 0 1\n') output.close() output2.close() output3.close() input.close()
def main(): functions.clear() if not functions.exists(): try: functions.intro() except KeyboardInterrupt: functions.clear() import sys sys.exit(0) functions.clear() try: password = getpass.getpass("Password: "******"Invalid password") import sys sys.exit(1) while True: functions.clear() print("Vault") print( "Use Ctrl+C to return back to this menu, or use it here to exit.\n" ) try: action = input( "1: Encrypt a file\n2: Download and encrypt a file from a URL\n3: Decrypt a file\n4: Change password\nSelect an option: " ) except: break action = action.strip().lstrip() try: action = int(action) except: continue if action not in [1, 2, 3, 4]: continue if action == 1: functions.clear() try: path = input("Please specify a file to encrypt: ") except KeyboardInterrupt: continue if functions.validate(path) and not path.endswith(".png"): functions.clear() try: response = input( "This file may be a valid image file. Convert to .png (y/n)? " ) except KeyboardInterrupt: continue if response.lower().lstrip().strip() == "y": temp = path path = functions.convert(path) delete = input("Delete original file (y/n)? ") if delete.lower().lstrip().strip() == "y": if not windows: temp = temp.replace("\\", "") try: directory = os.path.dirname(os.path.realpath(temp)) os.chdir(directory) os.remove(temp) except: pass functions.clear() try: save = functions.encodepath(path) if save == None: continue except Exception as e: print(str(e)) try: input("Invalid file path. Press enter to continue. ") except KeyboardInterrupt: continue continue else: try: input( "File encrypted.\nEncrypted file path: {}\nPress enter to continue. " .format(save)) except KeyboardInterrupt: continue continue elif action == 2: functions.clear() try: url = input("Please specify a file URL to download: ") except KeyboardInterrupt: continue name = os.path.split(url)[-1] base = os.path.dirname(os.path.realpath(__file__)) path = os.path.join(base, name) functions.clear() try: r = requests.get(url, stream=True) with open(path, 'wb') as out_file: shutil.copyfileobj(r.raw, out_file) except: try: input("Invalid URL: {}\nPress enter to continue. ".format( url)) except KeyboardInterrupt: continue continue if functions.validate(path) and not path.endswith(".png"): functions.clear() try: response = input( "This file may be a valid image file. Convert to .png (y/n)? " ) except KeyboardInterrupt: continue if response.lower().lstrip().strip() == "y": temp = path path = functions.convert(path) delete = input("Delete original file (y/n)? ") if delete.lower().lstrip().strip() == "y": if not windows: temp = temp.replace("\\", "") try: directory = os.path.dirname(os.path.realpath(temp)) os.chdir(directory) os.remove(temp) except: pass functions.clear() try: save = functions.encodepath(path) except: try: input("Invalid file path. Press enter to continue. ") except KeyboardInterrupt: continue continue else: try: input( "File encrypted.\nEncrypted file path: {}\nPress enter to continue. " .format(save)) except KeyboardInterrupt: continue continue elif action == 3: functions.clear() try: path = input("Please specify a .enc file to decrypt: ") except KeyboardInterrupt: continue functions.clear() try: save = functions.decodepath(path) except Exception as e: print(str(e)) try: input("Invalid file path. Press enter to continue. ") except KeyboardInterrupt: continue continue else: try: input( "File decrypted.\nDecrypted file path: {}\nPress enter to continue. " .format(save)) except KeyboardInterrupt: continue continue elif action == 4: try: functions.clear() current = input("Current password: "******"Passwords do not match. Press enter to continue. ") continue new = input("New password: "******"You will need to decrypt all files with your old password. Your new password will not be able to decrypt already encrypted files.\nRetype your password to confirm: " ) if confirm != new: input("Passwords do not match. Press enter to continue. ") continue functions.writepw(new) functions.clear() input("Password changed to: {}.\nPress enter to continue. ". format(new)) except KeyboardInterrupt: continue functions.clear()
def update(bake=False): def namespaced(n): return '%s:%s' % (name_space, n) cmds.currentUnit(time='pal') if not f.exists(scene_check_joints): exit_message = 'Not all joints from %s present in scene' % scene_check_joints sys.exit(exit_message) # Imports file in scene with a given name space import_file = cmds.fileDialog2(dialogStyle=2, fm=1)[0] name_space = os.path.basename(import_file).split('.')[0] + '_namespace' cmds.file(import_file, i=True, namespace=name_space) # Delete animation from joints in Biped hierarchy cmds.currentTime(0) cmds.select(f.get_joints()) cmds.cutKey() # Exports skin cluster weights for body meshes in scene all_meshes = f.get_meshes() head_meshes = [] search_pattern_r = '|'.join([sp for sp in search_pattern.split('\n')]) regex = r"\b.*(%s).*\b" % search_pattern_r for m in all_meshes: if re.search(regex, m): head_meshes.append(m) body_meshes = [m for m in all_meshes if m not in head_meshes] if body_meshes: cmds.select(body_meshes) sie.export_weights_sp() for sc in cmds.ls(type='skinCluster'): cmds.skinCluster(sc, ub=True, edit=True) # Deletes bind poses in scene cmds.delete(cmds.ls(type='dagPose')) # Checks if scene joints are scaled length = f.get_length(f.get_pos(length_joints[0]), f.get_pos(length_joints[1])) imported_length = f.get_length(f.get_pos(namespaced(length_joints[0])), f.get_pos(namespaced(length_joints[1]))) scale_factor = length / imported_length if round(scale_factor, 0) != 1: scaled_joints_group = cmds.group(namespaced(root_joint)) cmds.xform(scaled_joints_group, scale=(scale_factor, scale_factor, scale_factor)) # Aligns imported skeleton to the one in scene # All created constraints will be deleted alongside with imported mesh later cmds.pointConstraint(head_joint, namespaced(head_joint)) head_children_joints = cmds.listRelatives(head_joint, ad=True, type='joint') head_children_joints = filter_nubs(head_children_joints) for j in head_children_joints: if f.exists(namespaced(j)): f.unlock_attributes(j) cmds.pointConstraint(namespaced(j), j) cmds.orientConstraint(namespaced(j), j) # Keys all biped joints to prevent joints shift if bake: # Gets information about keyed range of imported bones ns_biped = [ namespaced(j) for j in f.get_joints() if f.exists(namespaced(j)) ] imported_biped_keys = cmds.keyframe(ns_biped, query=True, timeChange=True) ns_min, ns_max = min(imported_biped_keys), max(imported_biped_keys) cmds.bakeResults(f.get_joints(), time=(ns_min, ns_max + 1), sm=True) cmds.playbackOptions(min=ns_min, max=ns_max + 1) else: cmds.setKeyframe(f.get_joints(), time=0) cmds.namespace(removeNamespace=name_space, deleteNamespaceContent=True) # Imports all skin cluster weights for meshes in scene cmds.select(f.get_meshes()) sie.import_weights_sp() # Fix eyes joints pivot. # When bones are imported from another character sy = batch_skin_eyes.SkinEyes() sy.set_skin()