Quote:
Originally Posted by kovidgoyal
Seems awfully complicated. Why dont you just create a script that will extract the files from your archives with proper permissions instead, if you cannot find any program that does it for you. If you cannot figure out how to do it directly, then make it a two part operation, one that extracts the files to a temp dir, fixes their permissions, and then moves them over to the auto add dir.
Then just run your script instead of using whatever unarchiver program you are using currently.
|
So, write a special-purpose program which lists the contents of a zip file, lets me select the files I want (because I usually don't want everything that's in the archive, so I also need a GUI), and then extracts them into files with the right permissions. And what about other formats (rar, 7z, and what-all else that people use)? It gets messy, it turns into a non-trivial project.
Plan B, using a temp directory and all that as both you and betterred have suggested means that I have to (a) extract the files, and then (b) manually run something to fix the permissions. Or have (b) run (a), wait for process (a) to terminate, then continue with the moving etc.
In either case, the other issue is I have to remember to run my special program instead of just double-clicking on an archive. I might as well not bother using auto-add at all -- just extract into a temp directory and then drag&drop into Calibre.
At the moment I have a solution which involves no extra effort on my part -- I just extract the files into the auto-add directory. Every 30 minutes a batch file runs that checks if there are any files, fixes the permissions, creates and deletes a file, and goes back to sleep. Like I said, I could rewrite it easily enough and run it from startup or install it as a service -- but then it would be running even when Calibre ain't. So the plug-in solution seems better.
I'm imagining a plugin that kicks off a thread which will basically just sit in a loop which, with a bit of hand-waving, looks something like this:
Code:
while keepRunning:
gotfiles = False
for file in os.listdir(gprefs['auto_add_path']):
os.chmod(file,stat.S_IWRITE|stat.S_IREAD)
gotFiles = True
if gotFiles:
flagFile = os.path.join(gprefs['auto_add_path'],'foo.xxx')
open(flagFile,'a').close()
os.remove(flagFile)
time.sleep(loopDelay)
The big question is, is this feasible? Am I on the right lines?
[edit: Just caught up with your second one-liner, which would simplify the above code somewhat. Thanks.]