Python library to do path computation without an underlying file system - python-3.x

We have a project with data organized in a hierarchical way that can be seen as folders and files, but inside a database, not a true file system.
I want to write a CLI tool in Python that can do "ls", "cd", "rm", use Tab to autocomplete names.
The CLI tool should not be restricted to absolute paths but should be able to translate glob pattern or relative paths. For that reason, I'm looking for a Python library allowing path computation, something like os.path but that can work even if it is not a true file system.

Related

File name multiple extensions order

I want to create some bash scripts. They're actually going to be build scripts for Scala, so I'm going to identify them with my own .bld extension. They will be a sort of sub type of a shell script. Hence I want them to be easily recognised as a shell script. Should I call them
ProjectA.bld.sh //or
ProjectA.sh.bld
Edit: My natural inclination would be to go for the former but .tar.gz files seem to follow the latter naming convention.
A shell script doesn't mind what you call it.
It just needs to be..
executable (chmod +x)
in your path
contain a "shebang" as it's first line #!/bin/sh
The shebang determines which program is used to execute your script.
Call it ProjectA.bld.sh (or preferably buildProjectA.sh).
The .sh extension (although not necessary for the script to run) will allow you and everyone else to easily recognise it as a shell script.
While for the most part, naming conventions like this don't really matter at all to Unix/Linux, the usual convention is for the "extensions" to be in the order of the steps used to create the file. So, for example, a file named foo.tar.bz2.gpg.part01 would indicate a sequence of operations like the following:
Use tar to create foo.tar, which contains some other files
Use bzip2 to compress foo.tar into foo.tar.bz2
Use gnupg to encrypt foo.tar.bz2 into foo.tar.bz2.gpg
Use split or something similar to break the file into chunks for transmission/storage, resulting in one or more foo.tar.bz2.gpg.part* files.
The naming conventions are mostly just for human semantic meaning, though, and there's nothing stopping you from doing exactly the opposite, or even something completely random, except your own ability to remember exactly what you did...

Cross-platform paths in CMake

I have a project I can build on both Linux and Windows using CMake. The only issue is that Unix-style paths, in CMakeLists.txt, can't work on Windows (which uses backslashes instead of slashes, also requiring the drive letter).
Is there any way I can write a cross-platform CMakeLists.txt?
You question affects different details:
Just don't use backslashes. Windows will also process slashes.
Don't use drive letters. Use relative paths everywhere.
GET_FILENAME_COMPONENT(X "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) can solve the whole path without writing any absolute paths.
Add the tool binary paths into your PATH environment variable. So you do not need to search them by yourself (with absolute paths) or
Use FIND_PROGRAM() to get the tools absolute path without guessing around. You could add hints in which registry entries and paths cmake will search for the tool or
Consider to write your own module for every tool. You can copy the skeleton from any module of the modules folder (have a lock at FindJava.cmake; a very good and portable example on how to search a program).
If all those does not help, you can detect the platform by IF(WIN32) or IF(UNIX).
Hope, this helps...

Linux function name conflict MATLAB

I'm currently using a MATLAB software suite which includes a function called "Swap". Running this code on my personal machine runs just fine, but when attempting to run on a Linux server, it seems to be trying to use the built-in "Swap" function on the Linux terminal.
Is there some way that I can force the terminal to ignore this built-in Swap and simply call the "Swap" function which is part of the MATLAB suite?
Thanks!
Assumptions: When you said built-in "Swap" function on the Linux terminal, I am assuming you are talking about running MATLAB on the linux terminal itself. I am also assuming that the built-in swap command is something from the MATLAB platform and not the linux environment and this answer is based on these assumptions.
In a general case, when you would like to add a function file whose name is identical to an already exisiting function, you have to move the path of the function file to be added to somewhere above the path of the existing function file in the list of MATLAB search paths. The way it works is that when you mention the use of a function, MATLAB starts looking for a match from the top until the bottom of the list.
One can view the MATLAB search paths by running -
path
So, to answer your question, just add the path of the suite to the top of MATLAB search paths by using addpath -
addpath(PATH_TO_SUITE);
If PATH_TO_SUITE has subdirectories, one of which has the swap function file, use genpath along with addpath -
addpath(genpath(PATH_TO_SUITE));
This could be interesting too for you to follow - Access m-files in a subfolder without permanently adding it to the path.

Path variable: Find folder path of specific file

On Linux and other Unix-likes, how do I find the path to a specific file that I can use because of the PATH environment variable? For example, if I can use, from the command line:
ls # technically the file name is "ls.exe"
is there a way I can find the path of the ls.exe file explicitly without looking through the PATH variable myself (i.e. maybe have a program search through it but not look myself)?
I understand there are many pitfalls/caveats of doing this, for example a PATH can be a file or even part of a file (I think), plus symlinks, etc. could make it unreliable, but I'm looking for general use cases.
The reason I am asking is I have Windows with msysgit so I have A LOT of folders in my path, and searching every one would be annoying & time-consuming, not to mention harder because of Windows limitations, but I can still presumably use almost anything Linux can use.
$ type ls.exe
ls.exe is /usr/bin/ls.exe

File script searching for versioning

I need to search through all sub directories of a directory and find all files containing a "VERSION" string including a number.
I need to increment this number, so 1.1.2 will be incremented to 1.1.3 etc. and save it in the file again.
I need to run this on Windows machines only, if it makes any difference.
Can I do this with cmd commands or do I need to use a program for this ?
I would like to run this without installing anything if possible.
I ended up writing a Java program to go through the entire structure.
I found that using CMD commands was too complicated for me to structure, and using a Java program I could also easily reuse parts of the program in different but similar structures elsewhere in my file system.
The CMD usage could my the files for me, but extract a single line, manipulating it and putting it back inside the file was not easy using CMD commands, where as using Java was much easier.

Resources