Skip to content

Commit

Permalink
v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fardinkamal62 committed Mar 29, 2023
1 parent 00398e2 commit d079545
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# .idea folder of Jetbrains IDEs
.idea/
2 changes: 2 additions & 0 deletions LEARN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependent files, displaying brand name & version

**system_info.py** fetches system info such as Fedora version & architecture by
running the command `hostnamectl` with `grep` and gives the data back to **index.py**
- If the system is not Fedora, it will autoselect Fedora 36
- If the system is Fedora but version not specified, it will fetch the version from `hostnamectl` command

**scrape.py** used for scraping mirror list from Fedora mirror manager using `beautifulsoup4`. After fetching system info **index.py** calls this file
1. From Fedora version & architecture it fetches HTML of mirror manager e.g. `https://admin.fedoraproject.org/mirrormanager/mirrors/Fedora/38/x86_64`
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1><a href="https://github.com/fardinkamal62/fedora-mirror-measure">Fedora MiMe</a></h1>
<!-- Short description: -->
<h3>A Python script to measure Fedora mirror speed</h3>
<h6>version: 2.1.0</h6>
<h6>version: 2.2.0</h6>
</div>

<br>
Expand Down Expand Up @@ -37,6 +37,14 @@ After using MiMe I get around **2 Mbps!**
## Changelog

---
### 2.2.0:
- Fixed: download if file is not present
- Added: shows best mirror
- Autoselect Fedora 36 if run on distro other than Fedora

**Known Issues**
- Flags not rendering `speedtest.py:13:5`

### 2.1.0:
- Added support for Pre-Release
- Speedtest all the servers without typing **all**
Expand Down
2 changes: 1 addition & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import speedtest

name = "Fedora MiMe"
version = '2.1.0'
version = '2.2.0'

os.system('clear')
print(f"{name}")
Expand Down
33 changes: 25 additions & 8 deletions speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def code_to_country(code):


# Checking if Fedora version is pre-release or stable
def ping(ostm, archi):
def check_release(ostm, archi):
template = f"{ostm}/Everything/{archi}/os/images/efiboot.img"
pre_release_url = f'https://ap.edge.kernel.org/fedora/development/{template}'

Expand All @@ -25,13 +25,17 @@ def ping(ostm, archi):
return 'releases'


best_server = {'link': '', 'speed': 0.0}


def speed_test(links, ostm, archi):
version = ping(ostm, archi)
version = check_release(ostm, archi)
while True:
os.system('clear')
country_code = list(links.keys())
for i in range(len(country_code)):
print(f"{i + 1}: {code_to_country(country_code[i])}({len(links[country_code[i]])} {'mirrors' if len(links[country_code[i]]) > 1 else 'mirror'})")
print(
f"{i + 1}: {code_to_country(country_code[i])}({len(links[country_code[i]])} {'mirrors' if len(links[country_code[i]]) > 1 else 'mirror'})")

print("Leave blank: to test all mirrors")
country_code_number = input("\nEnter number separated by comma(enter q to quit): ")
Expand All @@ -49,14 +53,25 @@ def speed_test(links, ostm, archi):

print('\nStarting speedtest...\n')
for ccn in country_code_number:
print(f"\nChecking {code_to_country(country_code[int(ccn) - 1])} mirrors: {links[country_code[int(ccn) - 1]]}\n")
print(
f"\nChecking {code_to_country(country_code[int(ccn) - 1])} mirrors: {links[country_code[int(ccn) - 1]]}\n")
filtered_links = links[country_code[int(ccn) - 1]]
for link in filtered_links:
url = f"{link}/{version}/{ostm}/Everything/{archi}/os/images/efiboot.img"

with io.BytesIO() as f:
start = time.perf_counter() # starting time
r = requests.get(url, stream=True) # making requestL

# checking if file is in place
if r.status_code != 200:
if link.endswith('/linux'):
print(f"Skipping {link} \nReason: file not found\nError code: {r.status_code}\n")
continue
filtered_links.append(f"{link}/linux")
print(f"Skipping {link} \nReason: File might not be in place\nAdding into queue\n")
continue

total_length = r.headers.get('content-length') # file size
dl = 0
if total_length is None: # no content length header
Expand All @@ -69,8 +84,10 @@ def speed_test(links, ostm, archi):
sys.stdout.write(
f"\r{link} [%s%s] %s Kbps" % (
'=' * done, ' ' * (30 - done), dl // (time.perf_counter() - start) / 1000))

speed = dl // (time.perf_counter() - start) / 100000
print('\n')
if speed == 0.0:
filtered_links.append(f"{link}/linux")
speed = dl // (time.perf_counter() - start) / 1000
if speed > best_server['speed']:
best_server['speed'] = speed
best_server['link'] = link

print(f"Fastest mirror: {best_server['link']}\nSpeed: {best_server['speed']}")
6 changes: 3 additions & 3 deletions system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def architecture():

def os():
operating_system = hostnamectl('Operating System')
if re.search(r"^Fedora [1-9]+", operating_system):
print("Fedora Linux not found")
return None
if not re.search(r"^Fedora [1-9]+", operating_system): # if ran on non-fedora distro
print("Fedora Linux not found\nAutoselecting Fedora 36\n")
return 36
result = re.findall("\d+", operating_system)[0]
return int(result) # result = 36 // int

0 comments on commit d079545

Please sign in to comment.