Exemplo n.º 1
0
 def get(cls,
         start,
         stop=None,
         output_format="Elapsed time: %ts",
         float_length=4,
         float_operation="keep",
         return_time=False):
     if start not in Benchmark.timestamps or (stop != None and stop
                                              not in Benchmark.timestamps):
         if return_time:
             return -1
         else:
             warning("Benchmark error")
             return True
     start = Benchmark.timestamps[start]
     stop = Benchmark.timestamps[stop] if stop != None else time.time()
     elapsed = str(stop - start).split(".")
     if float_operation in "ceil" or float_operation in "ceil":
         if float_operation == "ceil":
             elapsed[0] = str(int(elapsed[0]) + 1)
         elapsed[1] = "0" * float_length
     elif float_operation in "round" and int(elapsed[1][0]) >= 5:
         elapsed[0] = str(int(elapsed[0]) + 1)
         elapsed[1] = "0" * float_length
     if float_length >= len(elapsed[1]):
         float_length = len(elapsed[1]) - 1
     elapsed[1] = elapsed[1][0:float_length]
     elapsed = ".".join(elapsed)
     if return_time:
         return float(elapsed)
     info(output_format.replace("%t", elapsed))
     return False
Exemplo n.º 2
0
 def used_without_options(self):
     for file in self.argv[1:]:
         path = self.ftp.sabspath(file)
         try:
             self.ftp.retrlines("RETR " + path, print(end=""))
         except:
             warning("Invalid file: " + file)
Exemplo n.º 3
0
 def used_without_options(selff):
     abs_path = self.ftp.sabspath(self.argv[1])
     if self.ftp.is_file(abs_path):
         self.del_file(abs_path)
     else:
         warning(
             "{} is not a filename (for directory use \" rm -d <directory>\")"
             .format(abs_path))
Exemplo n.º 4
0
 def used_without_options(self):
     for file in self.argv[1:]:
         try:
             if not self.ftp.exists(file):
                 file = self.ftp.sabspath(file)
                 self.ftp.mkd(file)
             else:
                 warning("File or directory already exists: " + file)
         except:
             error("You may not have permission to create folder: " + file)
Exemplo n.º 5
0
 def used_without_options(self):
     try:
         cmd = importlib.import_module("commands.{}".format(self.argv[1]))
         cls = getattr(cmd, self.argv[1])
         if cls.__doc__ == None:
             warning("Unavailable documentation")
         else:
             color(cls.__doc__, True)
     except:
         warning(
             "Command {} not found. Type help to get available commands".
             format(self.argv[1]))
Exemplo n.º 6
0
 def options_handle(self):
     options = self.argv[1]
     if "R" in options or "r" in options:
         for idx, el in enumerate(self.argv):
             if idx >= 2:
                 if self.ftp.is_dir(el) and self.ftp.is_empty(el):
                     self.del_dir(el)
                 else:
                     warning(el + " is not a directory or not empty")
     elif "D" in options or "d" in options:
         for idx, el in enumerate(self.argv):
             if idx >= 2:
                 self.del_recursive(self.ftp.sabspath(el))
     else:
         warning('invalid options')
Exemplo n.º 7
0
 def options_handle(self, path, opts=""):
     try:
         counter = 1
         with Capture() as stdout:
             self.ftp.retrlines("RETR " + path, print(end=""))
         for idx, el in enumerate(stdout):
             if "E" in opts or "A" in opts or "e" in opts:
                 el += "$"
             if "T" in opts or "t" in opts:
                 el = el.replace("\t", "^I")
             if "b" in opts and el != "" and el != "$":
                 el = "\t{} {}".format(counter, el)
             if "v" in opts or "A" in opts or "e" in opts or "t" in opts:
                 el = re.sub(r'[^\x00-\x7F]+', '^M', el)
             if "b" in opts and el != "" and el != "$":
                 counter += 1
             elif "n" in opts:
                 el = "\t{} {}".format(idx + 1, el)
             if not "s" in opts or ("s" in opts and el != "" and el != "$"):
                 print(el)
     except:
         warning("Invalid file: " + path.split("/")[-1])
Exemplo n.º 8
0
 def print_ls_with_options(self, path):
     path = self.ftp.sabspath(path)
     with Capture() as nlst:
         if "a" in self.argv[1] or "A" in self.argv[1]:
             self.ftp.retrlines("NLST -a " + path)
         else:
             self.ftp.retrlines("NLST " + path)
     if "l" in self.argv[1] or "L" in self.argv[1]:
         with Capture() as output:
             if "a" in self.argv[1] or "A" in self.argv[1]:
                 self.ftp.retrlines("LIST -a {}".format(path))
             else:
                 self.ftp.retrlines("LIST {}".format(path))
         self.colorize(output, nlst)
     elif "a" in self.argv[1] or "A" in self.argv[1]:
         with Capture() as output:
             self.ftp.retrlines("LIST -a {}".format(path))
         for idx, el in enumerate(output):
             file = nlst[idx]
             output[idx] = "[b][blue]{}[/endc]/".format(
                 file.replace("/", "")) if el[0] == "d" else file
         cprint("    ".join(output))
     else:
         warning("invalid options")
Exemplo n.º 9
0
 def handle_error(self):
     warning("This command takes no arguments")
     self.help()
Exemplo n.º 10
0
 def handle_error(self):
     warning("Command takes at least one file path")
     self.help()
Exemplo n.º 11
0
 def used_without_options(self):
     for file in self.argv[1:]:
         try:
             self.ftp.storbinary('STOR {}'.format(file), io.BytesIO(b''))
         except:
             warning("Could nor create file: " + file)
Exemplo n.º 12
0
 def handle_error(self):
     warning("This command takes only a path")
     self.help()
Exemplo n.º 13
0
 def used_without_options(self):
     try:
         path = self.ftp.sabspath(self.argv[1])
         self.ftp.cwd(path)
     except:
         warning('Directory may not exist or you may not have permission to view it.')
Exemplo n.º 14
0
 def handle_error(self):
     warning("Command takes at least a source file")
     self.help()
Exemplo n.º 15
0
 def handle_error(self):
     warning("Bad usage of help command")
     self.used_alone()
Exemplo n.º 16
0
 def handle_error(self):
     warning("Filename missing")
Exemplo n.º 17
0
 def help(self):
     if self.__doc__ != None:
         cprint(self.__doc__)
     else:
         warning("Unavailable documentation")