Exemple #1
0
 def sort_files_in_dir(self, path, dir_name):
     if len(os.listdir(path)) == 0:
         return
     files = help_functions.get_all_files_from_dir(path)
     dirs = []
     for file in files:
         dirs.append(self.translate_from_hash(file)[6])
     dirs.sort(key=lambda x: x.count(os.sep))
     dirs = help_functions.deduce_dirs(dirs)
     dict = self.create_dirs_in_list(dirs, path)
     self.move_files_in_dirs(files, path, dict)
Exemple #2
0
 def upload_mount_partition(self, name):
     if not self.unionpath.connected:
         print(color.red("Please connect to a sever in order to mount."))
         return
     hashdir = self.unionpath.translate_to_hash(
         name, self.unionpath.filesystem_root_dir)
     if not hashdir:
         while True:
             response = input(
                 color.yellow(
                     "{} does not exist. Do you want to create an empty partition? [y/n] -> "
                     .format(name))).lower()
             if response == "y" or response == "yes":
                 tmp = self.unionpath.current_folder
                 self.unionpath.current_folder = self.unionpath.filesystem_root_dir
                 hashdir = self.make_directory(name)
                 self.unionpath.current_folder = tmp
                 break
             elif response == "n" or response == "no":
                 return
     else:
         while True:
             response = input(
                 color.yellow("Mount {} to {}? [y/n] -> ".format(
                     name, self.unionpath.client.IP))).lower()
             if response == "y" or response == "yes":
                 break
             elif response == "n" or response == "no":
                 return
     self.unionpath.edit_dictionary(hash=hashdir,
                                    op='edit',
                                    name=name,
                                    property='mount')
     self.unionpath.edit_mount_list(op="add_mount",
                                    mounthash=hashdir,
                                    mountname=name)
     mountpath = os.path.join(self.unionpath.filesystem_root_dir, hashdir)
     if not os.listdir(mountpath):
         return "mnt {} {} {} {}".format("upload", hashdir, name, "True")
     else:
         files = help_functions.get_all_files_from_dir(mountpath)
         for file in files:
             self.unionpath.edit_dictionary(hash=file,
                                            op='edit',
                                            name=hashdir,
                                            property='mount')
         return "mnt {} {} {} {}".format("upload", hashdir, name, "False")
Exemple #3
0
 def send_all_files_of_dir(self, dir):
     files = help_functions.get_all_files_from_dir(dir)
     for f in files:
         self.send_file(f)