Linux/Python3 Look for a specific USB Flash Drive - python-3.x

I need a way to determine if a specific USB thumb drive has been inserted. For instance:
if "flash drive named "Records" is present":
copy data to drive
else:
"do something else"
I have all the copytree functions working just fine, I just need a way to check for the specific drive before the operation.
Thank you in advance!

By name, assuming you are looking for label, you could have a few ways. You could call blkid to get the labels of the system. But the tool itself might be limited to superusers. The target users might need to run your script as a superuser.
Other alternative I found with a little Google search is to use DBUS in Python. You might want to look up https://askubuntu.com/questions/437031/finding-volume-label-of-a-usb-mass-storage-device-using-python page.
In short, install python-dbus package and just a few lines of Python code could list you the drive labels.

How about the usbid package? It has the ability to find USB device IDs, so might be just what you need.
NB: I haven't used this myself; I just found this with a quick Google search and thought it might help solve your problem!

Your distro probably has the lsusb util installed. If so, you can have a look at this answer that demonstrated how to read and parse the output of lsusb from a python script.

Related

I have ext2 formatted file system Images. I like to read in terminal all the file system structures data in Linux specifically Ubuntu.Is there a tool>

So I have file system ext2 formatted image files. I like to view Inode, super block, filenames, etc. in the images for formatted file systsem . I like to know is there any tool for this. I need to view these structures like inode, superblock, file, related info like names of files, deleted inodes etc. In terminal, posssible some tool with available code in Linux. So can be editted the tool. Would be best if tool is coded in just C languange. Can anyone please do tell me this, Thanks again. Just opensource tool
I'm not certain I understood your question, but I think you probably just want to "loopback mount" your filesystem in a file. See here.
Failing that, I think you can use e2tools to access the contents. See here.

Make a minifilter like driver for linux

I'm new to the Linux file system. I wanted to use a mini filter like the driver for Linux, I came across various options like Hooks,DazukoFS(not used nowadays) fanotify. So I chose fanotify.
I want to modify a file before opening it. The similar work is performed by antiviruses they scan each file before opening.I'm not getting any method to do this task. Even not getting any proper documentation of fanotify using which I will be able to achieve this. I came across FAN_OPEN_PERM, again there was no example. Any help will be appreciated.
Thanks in advance.

linux kernel output in a file

I am using a program by using the linux kernel (in this case a predictor for protein localization). The output/results are printed in the linux kernel, one after each other. However, if I want to copy it to a simple textfile, the "length" of the kernel is not long enough for all the results.
instead of using smaller seperate files, I would like to print the output of the kernel to a file. I tried to google this, but it doesn't really help me futher.
1. dmesg seems to be for system-output stuff?
2. the /var/log/syslog.txt doesn't show the stuff I need, but other technical kernel stuff.
3. i saw something with printf(), but didn't quite understand the mechanics and if it was useable for my problem.
could someone explain how to do this or where to look for the right info?
I think i found out how to do it, by using > fileToBeNamed.txt at the end of the command, Sorry :(

How do I play a wav file from a Free Pascal application running on Linux?

I have a multi-platform application written in Free Pascal. This application plays a short sound on some event. On Windows, I can do this by MMSystem and sndPlaySound('sound.wav'). However, I don't know how to do this on Linux without external libraries.
I have a solution to play it with SDL and OpenAL, but I don't want any dependency on these libraries to play one short sound. Does there exist a Linux command line player that exists on most distros by default? The file format doesn't matter; I will convert it.
mplayer is command line and graphical. You can start it on tty and pty.
You could try aplay, but that has a dependency on ALSA. Maybe sox?
The program mplayer - "the movie player" gives you the option to use a graphical user interface or to use the console. So i would imagine it has a solution to your problem.
Are you looking to BEEP, BLEEP and BOOP and BOP ( and low frequency fart) ? Use sox. If youre looking to play a file: use sox or SDL.
You need a for looped array to get a sort-of piano effect, like a song. Its ugly, messy, and cant be tweaked much like the ole PC speaker, but its passable.
Beep is probably want you want, tho. Install the package, put one on your motherboard(YEAH...no hookup? use sox), and enable the pcspkr module. (On ubuntu its blacklisted by default.) If BEEP produces nothing, try sox.
At least youll have something. Yes, you can check for loaded modules and installed packages. I believe Ive done both.

New to Linux Kernel/Driver development

Recently, i began developing a driver of an embedded device running linux.
Until now i have only read about linux internals.
Having no prior experience in driver devlopment, i am finding it a tad difficult to land my first step.
I have downloaded the kernel source-code (v2.6.32).
I have read (skimped) Linux Device Drivers (3e)
I read a few related posts here on StackOverflow.
I understand that linux has a "monolithic" approach.
I have built kernel (included existing driver in menuconfig etc.)
I know the basics of kconfig and makefile files so that should not be a problem.
Can someone describe the structure (i.e. the inter-links)
of the various directories in the kernel-source code.
In other words, given a source-code file,
which other files would it refer to for related code
(The "#include"-s provide a partial idea)
Could someone please help me in getting a better idea?
Any help will be greatly appreciated
Thank You.
Given a C file, you have to look at the functions it calls and data structures it uses, rather than worrying about particular files.
There are two basic routes to developing your own device driver:
Take a driver that is similar to yours; strip out the code that isn't applicable to your device, and fill in new code for your device.
Start with the very basic pieces of a device driver, and add pieces a little at a time until your device begins to function.
The files that compose your driver will make more sense as you complete this process. Do consider what belongs in each file, but to some extent, dividing a driver among files is more an art than a science. Smaller drivers often fit into just one or two files.
A bit of design may also be good. Consider what you device does, and what your driver will need to do. Based on that, you should be able to map out what functions a device driver will need to have.
I also believe Linux Device Drivers, Third Edition may help you get on your way to driver development.
Linux files themselves include files based on what they do, what layer they are in, and what layer they access of the call stack. The Big Picture truly informs how each file is related to the next.
I had to fix a kernel driver once. My biggest tip (if you use vim) is to set it up with ctags so you can jump around the kernel source with ctrl-] every time you see a function you don't understand.

Resources