Linux MintThis forum is for the discussion of Linux Mint.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I cobbled up a little Python script to download the latest LinuxMint releases—both the main LinuxMint isos and the LMDE ones. You can find the script attached to this post.
It will look at the LinuxMint home page and extract the latest LinuxMint version, as well as the latest LMDE version, from the “Download” dropdown on the page. It will ask you if you want to download them (to the current directory), assuming by default that you will want to do so if you do not yet have the latest version.
To use it, you will first have to edit it and specify your preferred LinuxMint mirror site on the following line:
Code:
LINUXMINT_MIRROR_SITE = '<<<SPECIFY YOUR PREFERRED LINUXMINT MIRROR SITE HERE>>>'
To find the list of available mirrors, navigate to the download page of any LinuxMint or LMDE edition and scroll down to obtain the list of locations and the corresponding mirrors.
Feel free to use it or to not use it, as you see fit.
just some comments:
1. if you run basic linux commands like mv, chmod use shell, no python required.
2. all those run commands can be also implemented [not only in bash, but] within python too, which would be the preferred way (if you want to use python).
3. you did not make any error handling which makes the whole thing unreliable (at least you ought to print if that was successful or not and set exit code).
4. not to speak about some arguments instead of hardcoded values.
Let me start off by confirming that your comments are absolutely correct. Still, let me explain the rationale behind my decisions below:
Quote:
1. if you run basic linux commands like mv, chmod use shell, no python required.
Obviously. In fact, I started off trying to write the code in bash, but the regular expression handling got too complicated and ugly for my taste. That’s why I went looking for a more appropriate solution—for which I eventually selected Python.
Quote:
2. all those run commands can be also implemented [not only in bash, but] within python too, which would be the preferred way (if you want to use python).
Again, obviously. I actually tried various Python-based solutions, but in the end, I preferred the bash commands because of the familiar output that they produce. Bit lazy, perhaps, but works good enough for me.
Quote:
3. you did not make any error handling which makes the whole thing unreliable (at least you ought to print if that was successful or not and set exit code).
Well, if anything goes wrong, an exception will be raised. I deliberately specified the ‘check=True’ argument on my calls to the ‘run’ function to make sure that it will raise an exception if anything goes wrong. Again, rather lazy, but good enough for me.
Quote:
4. not to speak about some arguments instead of hardcoded values.
True. Initially, however, I did not consider publishing this (after all, rather “quick’n’dirty”) piece of code, so I didn’t bother.
In the end, if anyone finds anything of interest in the code, great. If not, well, then, so be it. Even if it can serve only as a “bad” example (for any definition of “bad”), I guess, it contributes at least something to the community.
It's a very odd thing to have a script for.
Is this homework, or some sort of excercise?
Not homework, no—it’s been ages since I left school, literally last century…
I’m just starting to appreciate Python, and I cobbled up this script mostly to get a feel for the regular expression features of the language.
Plus, I find it handy to run just a single command to get all the ISOs downloaded.
Of course, the script will work only as long as the LinuxMint website doesn’t get overhauled…
I’m just starting to appreciate Python, and I cobbled up this script mostly to get a feel for the regular expression features of the language.
Part of being a good developer is using the right tool for a task, and regex is not the best tool for parsing HTML.
You should update your script to use a more suitable tool (e.g. BeautifulSoup) for extracting the URLs from HTML, and limit the regex use to where it is more suited. (That may mean finding different tasks to explore it with.)
Also, formatting large regex patterns is a good idea, but over-formatting as you've done detracts from readability.
You should re-write your script to use a more suitable tool (e.g. BeautifulSoup) instead of regex, and find a more suitable task to explore Python's regex features.
Bwah… “Should” do such, “should” do so, … I’m just enjoying what I’m playing with, here. “Should” suffice, for now.
Having said that, I’m definitely not opposed to something like BeautifulSoup, just as I wasn’t opposed to exploring Python when things got too complicated and ugly for my taste in bash.
Quote:
Also, formatting large regex patterns is a good idea, but over-formatting as you've done detracts from readability.
True… It does allow me to keep track of where exactly I am in the pattern-matching operation while I’m working on it, though. May not work for everyone, but does for me.
Bwah… “Should” do such, “should” do so, … I’m just enjoying what I’m playing with, here. “Should” suffice, for now.
I reworded that bit of the post, but neglected to point out it was also in response to:
Quote:
Of course, the script will work only as long as the LinuxMint website doesn’t get overhauled…
i.e. using BeautifulSoup will allow you to make it less brittle.
Also, it is definitely a valid learning exercise to write the same thing using different languages/libraries, but for a usable script it makes sense to use appropriate tools.
using BeautifulSoup will allow you to make it less brittle.
Well, if BeautifulSoup simplifies the task as much, compared to Python, as Python did, compared to bash (and it sure does look like it does), then it certainly sounds like a good idea. Thanks for the pointer. Even just getting such a type of tip makes it worthwhile to share such a quick’n’dirty piece of code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.