I just need to refresh a folder.
A hypothetical ideal example would be:
from aModule import refreshdir # fake
refreshdir("C:\path\to\directory")
Context:
I am using Autodesk Desktop Connector, a service that sync data on the cloud with local folders. To avoid expending resources, this tool just checks for new updates when the user opens the file or refresh the directory (so manually). However, in order to automate some operations, I need to refresh the directory with Python. There is no API for this tool.
Thanks in advance! =)
Edit:
New files can be added in the cloud. That's why it is important to refresh the folder. Example:
Before refreshing:
enter image description here
After refreshing:
enter image description here
os.listdir cannot catch those highlited files before refreshing.
Refreshing a directory is not an operating system operation, but a function of the filesystem browser / explorer. A refresh is essentially just reading in the directory contents anew.
Most likely that Adobe tool is hooking into the filesystem functions that do this enumeration of a directory's contents. If this is the case, then the task should be as simple as
import os
os.listdir("C:/path/to/directory")
Keep in mind that backslashes (\) in standard string literals start an escape sequence, i.e. if you wanted to put an actual backslash there, you'd have to write "\\". However Windows will happily use forward slashes as directory separator as well, so you can just use that :-)
To solve this problem I created a script in Python using the pywinauto library to do a manually task that clicks on the file and then clicks on the Sync option.
In this case you'll need to know the name of the files you want to sync. The code was made to AutoCAD Plant 3D project, you'll need to change the path to your files.
from pywinauto import Application
raiz = "C:\\Users\\YOUR_USERNAME\\ACCDocs\\ORGANIZATION_NAME\\PROJECT_NAME\\Project Files\\PLANT3D_PROJ_NAME\\Plant 3D Models"
Application().start('explorer.exe ' + raiz, timeout=10)
explorer = Application(backend='uia').connect(path='explorer.exe', title="Plant 3D Models")
#Plant3DModels is a variable automatically created with the title of the windows opened
explorer.Plant3DModels.set_focus()
# 'Infra-Geral.dwg' is the name of the file that I will Sync
file = explorer.Plant3DModels.ItemsView.get_item('Infra-Geral.dwg')
file.right_click_input()
explorer.ContextMenu.Sync.invoke()
Related
I wanted to open the get-pip.py file in a new tab so that I could view it, but in Firefox, unlike Chrome, I cannot find a way to view code in a tab with an odd extension. When clicking on the code it asks if I want to download it, but I don't want to.
When I selected Firefox as the default program to open it (hoping it would just treat it like a text file or something, the same way Chrome handles odd extensions like .new) new tabs kept opening like a runaway freight train! It was difficult to get it under control and salvage my session.
Does anyone know how I may modify Firefox so that it will treat extensions like .py as a text file and open it in a new tab?
My version of your problem was solved like so: (on Linux)
cp /etc/mime.types ~/.mime.types # Note the dot in front of .mime
Edit ~/.mime.types, and comment out or delete everything but this:
text/plain asc txt text pot brf srt lua py
Add whatever file types you want to force as text/plain. In the above example, I added lua and py, they were not in the original /etc/mime.types.
Restart Firefox.
Note that this is for all apps that look at that/those files, not just Firefox. For example, if you run a web server, depending on the server, it may also affect that. This is why I did it in my home dir rather than /etc.
How I figured it out:
about:config
mime
This shows three settings:
helpers.global_mime_types_file /etc/mime.types
helpers.private_mime_types_file ~/.mime.types
plugin.java.mime application/x-java-vm
In my case I did not have the private file, so I did the copy/edit/restart as above.
Also Note: I can't get this to work for C files.
I need a component that's a browser-based file browser, and I expect some django app to currently provide this. Is there such a thing?
The full story:
I'm building a django app that is used for testing. I want to use it to serve files (and strings, and etc.) and attach custom headers to it.
Currently, I have a model FileSource which has a single file_path field, which is of type django.db.models.FileField.
When creating a FileSource from the admin, the user has a nice file upload dialog, and when saving, the file he chose, is saved on the server (in a really weird location, inside the directory where django is installed, or something weird like that, because i didn't customize the storage, nor will it help me in any way)
My problem: I only want to use the file dialog for the user to select a full path on the server. The file that the user chose must be only referenced, not copied (like currently), and it must reside on the server.
The server must thus be able to list the files it has, so i basically need a little browser-based file-browser.
At that point, I expect to be able to save a full path in my DB, and then I'll be able to access that file and serve it (together with whatever custom headers the user will chose from my app).
Currently, as you might know, the browsers always lie about the full path of the file. Chromium appends "C:\fakepath" to the file name, so I need support of the backend to accomplish this.
Also, I checked out django-filebrowser and django-filer and from what I understood, they weren't built for this. If I'm wrong, a little assistence in configuring them would be awesome.
You can use a FilePathField for that. It won't upload a file, but rather allow you to choose a pre-existing file. A caveat is that you can only use one directory. If you need multiple directories, then you'd need do go with something like django-filer.
Using an iPad, I'm attempting to import a text file from the Internet in order to utilize in Python MOOC exercise "hangman" from edx:
For this problem, you will need the code files ps3_hangman.py and words.txt. Right-click on each and hit "Save Link As". Be sure to save them in same directory. Open and run the file ps3_hangman.py without making any modifications to it, in order to ensure that everything is set up correctly.
Thing is, these seem not easy options on an iPad. I managed to copy and paste the hangman.py file into a new Pythonista file, but....
how to handle the large text file?
Where do I store it as a text file, find it, then import it into this iPad program?
No problem on Windows. Apple does not allow a file.open() type operation.
One way you could do this if you don't have access to a Mac/PC, i.e. entirely on your iPad in Pythonista:
Copy the URL of the text file in Safari (tap and hold the link)
In Pythonista, switch to the interactive prompt (swipe from right to left)
Enter the following two lines:
import urllib
urllib.urlretrieve('<paste copied url here>', 'words.txt')
You could also write these two lines in a regular script instead of using the interactive prompt. But you'll probably just need this once.
I'm trying to solve a question I have created about how to read the recorded date of the videos I took with a windows phone. It seems that the creation date are overwritten when the files are "sync" to my computer.
I'm trying to get around this by looking at the files in the phone directly. So I need to access to
"Computer\Windows Phone\Phone\Pictures\Camera Roll"
My problem is that I can only get os.chdir() to work on paths that has C:// as root
Any suggestions?
Update
I tried to place and run a file that prints the current directory.
Which gave me the result
C:\Users\<myUser~1.COM>\AppData\Local\Temp\WPDNSE\{<a lot of numbers and dashes>}
I am not familiar with Windows Phone paths in particular, but you should be able to figure out the "real" path by using the Windows file explorer to look at the properties of a file or folder. Right-click, choose Properties and look for a Location field.
Note that some "folders", such as the ones under "Libraries", are actually XML files pointing to multiple other locations.
Maybe the phone is connect via MTP.
How to access an MTP USB device with python
could help then.
[EDIT] They mentioned calibre there. The source code of calibre mabye already contain functions for getting file informations on mobile devices.
We test an application developed in house using a python test suite which accomplishes web navigations/interactions through Selenium WebDriver. A tricky part of our web testing is in dealing with a series of pdf reports in the app. We are testing a planned upgrade of Firefox from v3.6 to v16.0.1, and it turns out that the way we captured reports before no longer works, because of changes in the directory structure of firefox's temp folder. I didn't write the original pdf capturing code, but I will refactor it for whatever we end up using with v16.0.1, so I was wondering if there' s a better way to save a pdf using Python's selenium webdriver bindings than what we're currently doing.
Previously, for Firefox v3.6, after clicking a link that generates a report, we would scan the "C:\Documents and Settings\\Local Settings\Temp\plugtmp" directory for a pdf file (with a specific name convention) to be generated. To be clear, we're not saving the report from the webpage itself, we're just using the one generated in firefox's Temp folder.
In Firefox 16.0.1, after clicking a link that generates a report, the file is generated in "C:\Documents and Settings\ \Local Settings\Temp\tmp*\cache*", with a random file name, not ending in ".pdf". This makes capturing this file somewhat more difficult, if using a technique similar to our previous one - each browser has a different tmp*** folder, which has a cache full of folders, inside of which the report is generated with a random file name.
The easiest solution I can see would be to directly save the pdf, but I haven't found a way to do that yet.
To use the same approach as we used in FF3.6 (finding the pdf in the Temp folder directory), I'm thinking we'll need to do the following:
Figure out which tmp*** folder belongs to this particular browser instance (which we can do be inspecting the tmp*** folders that exist before and after the browser is instantiated)
Look inside that browser's cache for a file generated immedaitely after the pdf report was generated (which we can by comparing timestamps)
In cases where multiple files are generated in the cache, we could possibly sort based on size, and take the largest file, since the pdf will almost certainly be the largest temp file (although this seems flaky and will need to be tested in practice).
I'm not feeling great about this approach, and was wondering if there's a better way to capture pdf files. Can anyone suggest a better approach?
Note: the actual scraping of the PDF file is still working fine.
We ultimately accomplished this by clearing firefox's temporary internet files before the test, then looking for the most recently created file after the report was generated.