LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices


Reply
  Search this Thread
Old 05-16-2022, 06:08 AM   #1
luvr
Member
 
Registered: May 2005
Location: Boom - The Home Town of Tomorrowland, Belgium
Distribution: Slackware, Xubuntu
Posts: 459
Blog Entries: 2

Rep: Reputation: 194Reputation: 194
Python Script to Download LinuxMint


Hi all,

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.
Attached Files
File Type: txt linuxmint_download.txt (13.8 KB, 9 views)

Last edited by luvr; 05-16-2022 at 06:09 AM.
 
Old 05-16-2022, 06:15 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
Old 05-16-2022, 06:49 AM   #3
luvr
Member
 
Registered: May 2005
Location: Boom - The Home Town of Tomorrowland, Belgium
Distribution: Slackware, Xubuntu
Posts: 459

Original Poster
Blog Entries: 2

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by pan64 View Post
just some comments:
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.
 
Old 05-17-2022, 01:52 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
It's a very odd thing to have a script for.
Is this homework, or some sort of excercise?
 
Old 05-17-2022, 02:42 AM   #5
luvr
Member
 
Registered: May 2005
Location: Boom - The Home Town of Tomorrowland, Belgium
Distribution: Slackware, Xubuntu
Posts: 459

Original Poster
Blog Entries: 2

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by ondoho View Post
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…
 
Old 05-17-2022, 07:02 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by luvr View Post
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.


Last edited by boughtonp; 05-17-2022 at 07:21 AM.
 
Old 05-17-2022, 07:23 AM   #7
luvr
Member
 
Registered: May 2005
Location: Boom - The Home Town of Tomorrowland, Belgium
Distribution: Slackware, Xubuntu
Posts: 459

Original Poster
Blog Entries: 2

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by boughtonp View Post
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.

Last edited by luvr; 05-17-2022 at 07:27 AM.
 
Old 05-17-2022, 07:50 AM   #8
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,599

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546
Quote:
Originally Posted by luvr View Post
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.

 
Old 05-17-2022, 08:03 AM   #9
luvr
Member
 
Registered: May 2005
Location: Boom - The Home Town of Tomorrowland, Belgium
Distribution: Slackware, Xubuntu
Posts: 459

Original Poster
Blog Entries: 2

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by boughtonp View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sha256sum download frm linuxmint.com/verify.php contained PDF 6maureen52 Linux - Newbie 4 11-09-2020 09:39 AM
Cannot download any packages through terminal on LinuxMint Cinnamon 13 Maya. .deb packages only. daree361 Linux - Software 10 02-08-2017 01:48 PM
[SOLVED] LinuxMint 18 Host with LinuxMint 18 Guest in VirtualBox 5.1 Error TedCleggett Linux - Virtualization and Cloud 8 09-16-2016 02:40 PM
How to close open ports using a python script or a shell script in python ?? apanimesh061 Programming 3 11-20-2011 12:31 AM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration