Example #1
0
	def ls(self, cmds):
		if len(cmds) == 1:
			if "+" in cmds[0]:
				additional = True
			else:
				additional = False
			files = help_functions.get_files_from_current_dir(self.unionpath)  # "ls"
		else:  # error: too many arguments given
			print(help.helping(cmds))
			return
		if files: #if files has ben set, it went trough sucessfully and can be printed
			if len(files) > 20: #if there are more than 20 files to display: ask
				i = input("would you like to display all ({}) entries? [y/n]: ".format(len(files))).lower()
				if i == 'y':
					self.executions.list_folder_content(files, True, additional=additional)
			else:
				self.executions.list_folder_content(files, additional=additional)
Example #2
0
 def ls(self, cmds):
     if len(cmds) == 1:
         if "+" in cmds[0]:
             additional = True
         else:
             additional = False
         files = help_functions.get_files_from_current_dir(self.unionpath)
     else:
         print(help.helping(cmds))
         return
     if files:
         if len(files) > 20:
             i = input(
                 "would you like to display all ({}) entries? [y/n]: ".
                 format(len(files))).lower()
             if i == 'y':
                 self.executions.list_folder_content(files,
                                                     True,
                                                     additional=additional)
         else:
             self.executions.list_folder_content(files,
                                                 additional=additional)
Example #3
0
 def remove_object(self, name, suppress=False):
     try:
         obj_hash, os_obj_path = self.unionpath.get_full_path(name)
     except:
         return
     hashes = [obj_hash]
     if os.path.isfile(os_obj_path):
         os.remove(os_obj_path)
         filehashes = [obj_hash]
         return hashes, filehashes
     elif os.path.isdir(os_obj_path):
         filehashes = []
         if len(os.listdir(os_obj_path)) == 0:
             empty = True
         else:
             empty = False
         if not empty:
             tmp = self.unionpath.current_folder
             os.chdir(os_obj_path)
             self.unionpath.current_folder = os.getcwd()
             files = help_functions.get_files_from_current_dir(
                 self.unionpath)
             os.chdir(tmp)
             self.unionpath.current_folder = tmp
             if not suppress:
                 while True:
                     show_content = input(
                         color.yellow(
                             "Folder {} is not empty. Display content? [y/n/stop]"
                             .format(name)))
                     if show_content.lower() == "y" or show_content.lower(
                     ) == "yes":
                         self.list_folder_content(files)
                         break
                     elif show_content.lower() == "n" or show_content.lower(
                     ) == "no":
                         break
                     elif show_content.lower() == "stop":
                         return
                     else:
                         print(
                             color.red(
                                 "Please enter [y/n], if you want to stop the deletion enter [stop]."
                             ))
                 while True:
                     show_content = input(
                         color.yellow(
                             "Delete all content of {}? [y/n]".format(
                                 name)))
                     if show_content.lower() == "y" or show_content.lower(
                     ) == "yes":
                         for (dirpath, dirnames,
                              filenames) in os.walk(os_obj_path):
                             hashes.extend(filenames)
                             filehashes.extend(filenames)
                             hashes.extend(dirnames)
                         shutil.rmtree(os_obj_path)
                         return hashes, filehashes
                     elif show_content.lower() == "n" or show_content.lower(
                     ) == "no":
                         return
             else:
                 for (dirpath, dirnames, filenames) in os.walk(os_obj_path):
                     hashes.extend(filenames)
                     filehashes.extend(filenames)
                     hashes.extend(dirnames)
                 shutil.rmtree(os_obj_path)
                 return hashes, filehashes
         else:
             shutil.rmtree(os_obj_path)
             return hashes, filehashes