Explorar o código

Copie: ajoute un degré d'interpretation (pas opé)

olinox %!s(int64=7) %!d(string=hai) anos
pai
achega
3688b8d560
Modificáronse 1 ficheiros con 47 adicións e 15 borrados
  1. 47 15
      core/nlp.py

+ 47 - 15
core/nlp.py

@@ -30,14 +30,18 @@ def submit(command):
     command_index = -1
     for i, token in enumerate(doc):
         if token.lemma_ in ("copy", "delete", "rename", "move", "open", "new", "create"):
-            command = token
-            command_index = i
-            break
+            if not command:
+                command = token
+                command_index = i
+                break
+            else:
+                return "Hey! Une commande à la fois svp, je ne suis qu'en beta."
 
     if not command:
         return "Je n'ai pas compris votre demande"
     logger.info("Commande: %s", command)
 
+    # Détaille les arguments de la commande
     if command.lemma_ == "copy":
         args = doc[command_index + 1:]
         what = ""
@@ -45,12 +49,39 @@ def submit(command):
 
         for token in args:
             if not what:
-                if Path(token.text).abspath().isfile():
-                    what = Path(token.text)
+                if Path(token.text).expandvars().isfile():
+                    # chemin absolu vers un fichier existant
+                    what = Path(token.text).expandvars()
+                    continue
+                if Path(token.text).expandvars().abspath().isfile():
+                    # chemin relatif vers un fichier existant
+                    what = Path(token.text).expandvars().abspath()
+                    continue
+                if Path(token.text).expandvars().isdir():
+                    # chemin absolu vers un repertoire existant
+                    what = Path(token.text).expandvars()
+                    continue
+                if Path(token.text).expandvars().abspath().isdir():
+                    # chemin relatif vers un repertoire existant
+                    what = Path(token.text).expandvars().abspath()
                     continue
+
             if not where:
-                if Path(token.text).abspath().isdir():
-                    where = Path(token.text)
+                if Path(token.text).expandvars().isdir():
+                    # la cible est un répertoire existant (chemin absolu)
+                    where = Path(token.text).expandvars()
+                    continue
+                if Path(token.text).expandvars().abspath().isdir():
+                    # la cible est un répertoire existant (chemin relatif)
+                    where = Path(token.text).expandvars().abspath()
+                    continue
+                if Path(token.text).expandvars().parent.isdir():
+                    # la cible est un répertoire inexistant (chemin absolu), mais son parent existe
+                    where = Path(token.text).expandvars()
+                    continue
+                if Path(token.text).expandvars().abspath().parent.isdir():
+                    # la cible est un répertoire inexistant (chemin absolu), mais son parent existe
+                    where = Path(token.text).expandvars().abspath()
                     continue
 
         if not what or not where:
@@ -104,14 +135,15 @@ def print_analyse(doc):
 
 if __name__ == "__main__":
 
-    file_init_a = Path(__file__).parent.parent / "test" / "init" / "a.txt"
-    dir_a = Path(__file__).parent.parent / "test" / "work"
-    file_a = Path(__file__).parent.parent / "test" / "work" / "a.txt"
-    file_b = Path(__file__).parent.parent / "test" / "work" / "b.txt"
+    HERE = Path(__file__).parent
+    TEST_DIR = HERE.parent / "test"
+    TEST_I_DIR = TEST_DIR / "init"
+    TEST_W_DIR = TEST_DIR / "work"
 
-    file_init_a.copy(file_a)
+    logger.info(submit(r"Copy from {} in {}".format(TEST_I_DIR / "a.txt", TEST_W_DIR)))
+    logger.info(submit(r"Copy {} to {}".format(TEST_I_DIR / "a.txt", TEST_W_DIR)))
+    logger.info(submit(r"Copy {} to {}".format(TEST_I_DIR / "a.txt", TEST_W_DIR.relpath(HERE))))
+    logger.info(submit(r"Copy {} to {}".format((TEST_I_DIR / "a.txt").relpath(HERE), TEST_W_DIR)))
 
-    logger.info(submit(r"Copy from {} in {}".format(file_init_a, dir_a)))
-    logger.info(submit(r"Copy {} to {}".format(file_init_a, dir_a)))
-    logger.info(submit(r"Delete {}".format(file_init_a)))
+    logger.info(submit(r"Delete {}".format(TEST_I_DIR / "a.txt")))
     # submit(r"Rename .\test\work\a.txt in .\test\work\b.txt")