PythonWebkit default directory listing - python

I want to change the default directory listing of the pythonwebkit(the one imported from gi.repository) for an application I am working on. Is there any function/script in webkit that does the job?

EDIT
The code for styling the default directory listing is in the file net/base/dir_header.html and ends up in chrome.pak and chrome_100_percent.pak.
The python module data_pack.py can work with these files.
If you want to filter certain file types from the list, you can probably do that in addRow()
You will have to use os.chdir() to change the current directory for the whole process. AFAIK, WebKit doesn't keep an internal environment for things like the current folder.

Related

How to refresh a directory (Windows 10) using python

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()

why is desktop.ini file created?

I made a program using tkinter (GUI module). basically it is a banking system that stores data in text files. I found that a desktop.ini file was created in that folder. why so? Is it harmful if I delete the file?
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,27
[ViewState]
Mode=
Vid=
FolderType=Generic
👆 this is what is there in that file.
it's a windows config file and is not harmful or a vulnerability
According to https://answers.microsoft.com/en-us/windows/forum/all/there-are-these-random-desktopini-files-appearing/5bb923f5-6b06-4e07-a79e-a16c8bfc844a
You should not delete them.
A Desktop.ini file is a file that determines the way a folder is displayed by Windows. These files can be found in any folder, anywhere on your computer, as long as that folder has a custom appearance set for it. Desktop.ini files control things like the icon used for that folder and its localized name.
Deleting them will always regenerate them anyway. If you don't want to see them, turn off show hidden files and folders in File Explorer > View tab > uncheck hidden files.

How to include data files and directories that need to be changed or added with Pyinstaller?

The script needs to read from a .txt file with a list of items and based off that list, it creates a directory for each item. So just a simple with open() statement and then os.mkdir()..
The client will add account names to the txt file when they get new accounts, the program will create new directories for those new accounts. Files that are then placed in each directory for those accounts will get pandas stuff done to them and moved to an archive folder along with logging the events.
Since the program will be used by non-programmers, I'm using Pyinstaller.
When I go through the process, including the --add-file attribute, run the program, it says the txt file doesn't exist. I think I have an idea how to fix that but when I got the os.mkdir and with open statements to work by separating them out, it created them in the home folder and not the program folder. Path issue? And I only see documentation on how to include data files but not how to include changeable files.

Exporting a dataframe to CSV to the same directory as the exporter script

Pardon if I couldn't synthesize precisely my problem with my title, however I guess that by explaning it, things will get more clear.
My problem is the following: I am sending a file containing two scripts to a client, one of them generates a set of articial data, in the form of a dataframe, and the other to import and process that data. So, I want my exported csv to be on the same folder as the script that will generate it, however I don't want to write the usual path manually, as I would write on my PC, because I am sending the file to someone else.
df.to_csv(r'Path where you want to store the exported CSV file\File_Name.csv')
So, lets say that the scripts are in a folder named "A", is there somehow to setting the generated CSV to be saved on this specific folder, a parent folder, as well as being imported by the second script, without having to write the whole folder path that I would normally do if I were on my PC?
I expect something like this:
df.to_csv(r'...\A\File_Name.csv')
You can import os and then use
os.getcwd()
It will give you the path that the script is running from, from there you can
access any directory from that path so:
df.to_csv(os.getcwd() + r'\A\File_Name.csv')
You can use dot as relative path. ./ means current directory, ../ means parent directory.
df.to_csv('../File_Name.csv') means save the csv file to parent directory.
df.to_csv('./A/File_Name.csv') means save the csv file to subfolder A.
By the way, dot relative path and the other answer os.getcwd(), work with where the script runing, not where the script exists.
like this python script/data.py, ./ means the directory of script directory, not the directory of data.py, same as os

Having trouble ignoring files in Rsync?

Alright, I have two folders that need to be in sync, but certain files need to be ignored before the first upload.
To make sense of what I mean lets say for example I have a folder called src and another folder called dest.
src contains settings.properties, some python code, and a template properties file.
dest contains the same settings.properties, same python code but the template properties file is populate during the sync process (done by a script that wraps the protocol)
Now, if I decide to modify the python code in dest, the python code should be updated in src folder, but the new template.properties which is populated should be ignored.
I tried using excludes and includes but I read that you can't use both because "includes takes precedence"
Using Windows, and I am currently using a python script that formats the paths to the default "/cygdrive/C/" then I populate the properties file, then I run rsync

Categories

Resources