Replies: 4 comments 2 replies
-
Can you give more details about the surrounding workflow for that?
If you just need to copy some files / folders around, I'm not sure it's worth going through the papis API. |
Beta Was this translation helpful? Give feedback.
-
At the moment I provide a list of directories (the marked ones from dired) to the script. These directories are then used via papis api to find the docs: # ==============================================================================
dirsL = sys.argv[1:]
# ==============================================================================
# searchPattern = ".*"
# searchPattern = "tags: CLEAN"
searchPattern = "*"
sourceL = []
dstL = []
for dir in dirsL:
print(" ")
print(100 * "=")
print(100 * "=")
print(" FOLDER: ", dir)
print(100 * "=")
docs = papis.api.get_documents_in_dir(directory=dir, search=searchPattern)
for doc in docs:
print(100 * "-")
print(" Current directory: ", dir)
print(" - Search Pattern: ", searchPattern)
print(100 * "-")
print(" - keys: ", doc.keys())
print(" - title: ", doc["title"])
files = doc.get_files()
main_folder = doc.get_main_folder()
main_folder_name = doc.get_main_folder_name()
print(" - mainfolder: ", main_folder)
subfolder_name = main_folder.split(rootDir)[1]
for file in files:
file_name_to_check = file
if is_file_in_current_or_subfolder(file_name_to_check):
print(" - files: ", files)
print(" - file: ", file)
print(" - TAGS: ", doc["tags"])
print(100 * ".")
tags_init = doc["tags"]
createDir(dstDir + subfolder_name)
source = file
# TODO - check if file in current subfolder
destination = dstDir + subfolder_name
print(" - Copy to destination folder: ", destination)
p = Popen(["cp", source, destination], stdout=PIPE, stderr=STDOUT)
output, _ = p.communicate()
output = output.strip().decode("utf-8")
if p.returncode:
print(f"E: {output}")
else:
print(output)
doc["transfer-cloud"] = "inCLOUD"
doc["transfer-cloud-date"] = datetime.today().strftime("%Y-%m-%d %H:%M:%S")
papis.api.save_doc(doc)
print(100*".")
print( " Copied and Papis Tags changed to : inCLOUD")
sourceL.append(source)
dstL.append(destination)
print(100*"=")
print( "Copied files (source file / destination folder)")
for i, source in enumerate(sourceL):
print(source)
print(100*"-")
for i, dst in enumerate(dstL):
print(dst) And after copying I set the the item Thank you! |
Beta Was this translation helpful? Give feedback.
-
ok, this works for directly selected document folders. Not directly if I am selecting a parent folder where all sub documents need to be copied, but I think this can also be done outside the papis api. thank you! |
Beta Was this translation helpful? Give feedback.
-
just in case someone needs it (defun papis-transfer-to-cloud-marked-dired-folder-toCLOUD ()
"The marked Dired files (if any) are appended as arguments."
(interactive)
(let* ((files (mapcar #'shell-quote-argument (dired-get-marked-files))) ;; Get marked files
(cmd (format "python papis_api_tablet_sent_to_cloud_dired_marked_toCLOUD.py %s" (string-join files " "))) ;; Append files
(buffer (get-buffer-create "*Papis Transfer all back*"))) ;; Create buffer
(with-current-buffer buffer
(erase-buffer) ;; Clear buffer before running command
(insert (format "Running: %s\n\n" cmd)) ;; Show command at top
(ansi-color-for-comint-mode-on) ;; Enable ANSI colors
(comint-mode)) ;; Use comint-mode for better process handling
;; Start process with proper shell execution
(let ((process (start-process-shell-command "Papis TRansfer all back" buffer (concat "bash -c \"" cmd "\""))))
(set-process-filter process #'my-ansi-colorize-buffer) ;; Apply colorization
(pop-to-buffer buffer)))) ;; Open buffer and the python from subprocess import Popen, PIPE, STDOUT
from datetime import datetime
debug = False
import papis.api
import papis
import sys
import os
import shutil
def is_file_in_current_or_subfolder(file_name):
current_directory = os.getcwd()
if debug:
print(100 * "a")
print(current_directory)
for dirpath, _, filenames in os.walk(current_directory):
if debug:
print(100 * "-")
print(dirpath)
print(100 * ".")
print(filenames)
if os.path.basename(file_name) in filenames:
return True # File found
def createDir(directory):
if not os.path.isdir(directory):
os.makedirs(directory, exist_ok=True)
# ==============================================================================
rootDir = "/PAPIS_DB/"
dstDir = "/00_PAPIS_Cloud/"
# ==============================================================================
dirsL = sys.argv[1:]
print(dirsL)
print("test")
# ==============================================================================
# searchPattern = ".*"
# searchPattern = "tags: CLEAN"
searchPattern = "*"
sourceL = []
dstL = []
for dir in dirsL:
print(" ")
print(100 * "=")
print(100 * "=")
print(" FOLDER: ", dir)
print(100 * "=")
# docs = papis.api.get_documents_in_dir(directory=dir, search=searchPattern)
doc = papis.document.from_folder(dir)
print(100 * "-")
print(" Current directory: ", dir)
print(" - Search Pattern: ", searchPattern)
print(100 * "-")
print(" - keys: ", doc.keys())
print(" - title: ", doc["title"])
files = doc.get_files()
main_folder = doc.get_main_folder()
main_folder_name = doc.get_main_folder_name()
print(" - mainfolder: ", main_folder)
subfolder_name = main_folder.split(rootDir)[1]
for file in files:
file_name_to_check = file
if is_file_in_current_or_subfolder(file_name_to_check):
print(" - files: ", files)
print(" - file: ", file)
print(" - TAGS: ", doc["tags"])
print( far from perfect but seems to twork... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I would like to copy all marked folders and subfolders in emacs to my cloud directory.
It seems that with
get_documents_in_dir
I get all documents in the current or selected folders as long as I can provide a good search pattern:So this works
with
But I actually would like to copy all documents in my selected directories, not only the ones with a certain tag.
What search pattern do I need to choose? I tried something like
.*
or*
but this does not seem to work.Does anyone have an idea?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions