Updating the question.
I am developing a command-line tool for a framework.
and I am struggling with how to detect if the current directory is a project of my framework.
I have two solutions in mind.
some hidden file in the directory
detect the project structure by files and folders.
What do you think is the best approach?
Thank you,
Shay
Thank you very much
In my opinion, a good idea would be to either have a project directory structure that you can use a signature for the project/framework, that you can use within the tool as a list of signature-like structures, for example
PROJECT_STRUCTURE_SIGNATURES = [ "custom_project", "custom_project/tests", "custom_project/build", "custom_project/config", "config/environments" ] and then just check if any(signature in os.getcwd() for signature in PROJECT_STRUCTURE_SIGNATURES).
if the project structure is not too complex, I suppose that would be a start in order to identify the requirements that you're looking for.
However, if this is not the case, then I suppose a dictionary-like structure that you could use to traverse the key-value pairs similar to the project's file structure and check the current directory against those would be a better idea, where if none of the elements from the nested dictionary traversal matches, then the directory is not within the project structure.
Related
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
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.
"""
So I'm building a pipeline that is not going into a real production environment. Basically, I have some data in a defined folder structure, and I want to access it from different stages in my pipeline. Right now, data is ordered kind of like this
.../data/03-14-2019/unprocessed/raw/student_id_12345-raw.csv
or
.../data/05-04-2020/processed/position/student_id_1234345-position.csv
Now, I wrote a modular pipeline that looks in a folder and runs the pipeline all the .csv files in all the contained directories. If I point it at .../data/03-14-2019/unprocessed/raw/ then my pipeline will process all of the raw data for every student. I built this under the assumption that we were going to rename all the files to a more manageable schema, but things may have changed. My question is this: Using the os.link() functionality in python3, would it be possible to make an alternate filepath system that includes what I want? For example, one way I may want to go through files might be:
.../data/unprocessed/student_id_12345/2019/03/14/raw/student_id_12345-raw.csv
or maybe
.../data/unprocessed/raw/2019/03/14/student_id_12345/student_id_12345-raw.csv
depending on if I want to process a certain batch of students or only raw data from a certain day. I remember using a batch renaming tool as part of either Total Commander or Nautilus, but I don't remember if it could do symbolic links. Basically, I want to use symbolic links to build a directory structure on top of an existing structure.
I was going to try implementing this, but I figured I should check if anyone has already done this or there were already solutions before I started, as well as maybe some suggestions of where to start. Thanks!
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
So I trying to come up with a script to check and report files from my sharepoint according to some criteria. I need however authenticate using the company Active Directory.
I have done some research and all I've found seem far too advanced for what I intend and would prefer not to spend the whole time learning django custom auth. Haufe.sharepoint seems simpler, but I didn't manage to list all folders from a URL with it.
I must confess I don't really understand Sharepoint very much either, though I'm assuming it could behave sorta like a file repository for my purpose. So I will not be offended if someone points out that what I’m trying to do doesn’t make sense.
Anyways, I have an url like http://intranet/sharedir/Archive/Projects/Customer1 and under it many folders containing subfolders and files.
What I want is, given the URL (like the one above), list all directories and files contained. After that I will iterate over the items and apply the rules I’m interested.
If someone could provide some Python code example or reference would be great.