django way to get and save a tree of folders and files - python

When I came across a project to save a tree of files - means including subdirectories and files, not just files - I couldn't find an appropriate solution for the problems.
note: This question is not the same as this.
They speak of two different things, mine: How to save, his/hers: How to show - a tree of files
I do not want to write the code purely by myself or use a library that isn't suggested by Django.
To understand better, let me say a user will upload these three files:
src/statistics
test/tests
img/9744t3vo5.png
though files can be placed in root or home or any other place in the file system (let me say simpler: files path should be relative)
But the problem is how to get & save files in that manner (with relative path took effect) not the issue to show files that is solved in the question linked above

Related

Create direct file object in python

I have images in 100 folders and the search results are slow, so I want to access those images, so maybe I wanna do it with python(if it is faster), in the way that when we select all the files, and drag and drop them in windows. then I realized that drag and drop in windows uses Component Object Model this source.
So I want to know is there any way in python to have COMs of the image files in those 100 folders in the same place (a specific folder)? or in other words can we create COMs of other files, (equivalent of shortcuts), cause I know shortcuts for my purpose won't work.
The question in general is about how to access direct handles or COMs of files of different folders in one folder? if it's possible, please tell me how? to be simpler I want to have similar function of file shortcuts but not 'shortcuts' existing in windows, because for my purpose 'shortcuts' won't work, so I think it can be done with COMs.
tkinter equivalent question:
let me ask my question in other way, lets think I want to make a windows file search application in python with some library like tkinter, so one background part of my code finds the file paths of desired search results, and other part in gui('gui part'): wants to show the result files with ability of opening files from that gui or drag files from gui to other folder or applications, so how should I do the 'gui part'?
this tutorial suggested by #Thingamabobs is about getting external files into window(gui) of app, but I want the opposite, I mean having file handles to open, something like windows explorer
My question maybe wrong in case of misunderstanding the concept of COMs, so please provide me more relevant sources of use case of mine. finally if the title seems to be unsuitable, feel free to change it.
Based on an interpretation of the question, the following is an initial summary approach to a solution.
"""
This module will enable easy access to files spread across 100 plus
directories. A file should be as easy to open as clicking on a link.
Analysis:
Will any files be duplicated in any other directory? Do not know.
Will any file name be the same as another file in a different directory? Do
not know.
Initial design in pseudocode:
> Capture absolute path to each file in each directory.
> Store files information in python data structure
> for instance a list of tuples <path>,<filename>
> Once a data structure is determined use Tkinter, ttk.treeview to open a
file as easy as clicking on a link in the tree.
"""

How to detect and separate Corrupt/Unreadable PDFs and password protected PDFs from a directory using python?

I have a directory containing about ~ 1,00,000 multipage PDFs.
I want to separate Corrupt/Unreadable and Password protected PDFs from this directory using python.
Need a good and fast solution as I might need to do it for large number of files in future.
Thanks in advance.
You can try to use PyPDF2. Loop over all files in the directory using os.listdir() and try opening each one, and store the name of each one that gives you an error. You can also place them in two different directories depending on whether opening a file gives you an error using simple try/except.

Is wildcard import considered "acceptable" when using it to allow folder structure in step definition container?

Currently I'm working on automation in a project that has a very big site divided in sections and/or pages.
I'm using python-behave for the first time and I'm still learning (used to work with ProtractorJS)
Since I started I've been using the steps folder to put all my step files (each page has it's own step file) but in my case, it's not going to be scalable since the site has around 50 pages, with subsections each, so having all step files in one folder is going to get messy as I start adding files to the step folder.
What I want to do is be able to have folders to separate each of the pages and have step files in each of them to better organize the files.
Now, I know that this framework does not support having a folder structure inside the step definition folder, so i started looking around and found this post with a possible solution, but i noticed he uses wildcard import to add all nested step files.
I know wildcard imports are not considered a good practice in general, but i feel in this case is the only way to allow folder strucures for step files.
Is there any other way to achieve this?
Example
features
-->steps
---->*.py // This is where pyhton-behave expects to find the step definitions. The "recommended" way
What i'm trying to do
features
--->steps
----->login
-------->login_steps.py
----->some_page
-------->some_pages_steps.py
--->all_steps.py // file that imports nested step files using wildcard
// the only file that behave finds when looking for steps

Want to compile all the images in a folder and its subfolders to pdf file with names

I am just a beginner in Python. So help me learn and write the code for a small but complex problem. I've tried many things but I am lost where to start with and go:
Problem:
I have a folder and its subfolders with heaps of different product images(let's say in .jpeg and .png). I want to compile a single pdf of all these photos with links/location of these photos in the pdf. This list and photos could be in the form of a table or a very simple format.
I am doing it because sometimes I forget the product name so I have to look at its image by going into each folder and sub-folder. This will give me an opportunity to look at all the photos in these folders and sub-folder without opening them one-by-one.
Your issue breaks down into 3 steps.
1-Search the directories for files (which you can use the os module's walk()).
here is a great tutorial:
https://www.pythoncentral.io/how-to-traverse-a-directory-tree-in-python-guide-to-os-walk/
2-add the found files into a list of tuples having path of the image and the name of it.
3- Add these images into a single pdf file. You can use python module fpdf to do this. And this has been addressed already here:
Create PDF from a list of images

Manage #TODO (lots of files) with VIM

I use VIM/GVIM to develop my python projects and I randomly I leave #TODO comments in my code.
Is there any way to manage (search, list and link) all the #TODO occurrences inside VIM? I tried the tasklist plugin, it's almost what I need, but it only lists the current file #TODO occurrences. Generally my projects has some sub-folders and many .py files, so I'd like to find a way to search through all folders and files in the current working directory and list them.
If you just want a list of the occurences of "TODO" in .py files in the working directory, you can just use :vimgrep like so:
:vimgrep TODO **/*.py
Then open the quickfix window with:
:cw
(it might open it automatically anyway, not sure) and just scroll through the results, hitting Enter to go to each occurrence.
For more complicated management, I'd probably recommend setting up an issue tracker.

Categories

Resources