pamir.py
À propos
- Type de fichier
- Fichier PY de 2 Ko (text/x-python)
- Confidentialité
- Fichier public, envoyé le 26 juin 2013 à 16:01, depuis l'adresse IP 82.227.x.x (France)
- Sécurité
- Ne contient aucun Virus ou Malware connus - Dernière vérification: 3 jours
- Statistiques
- La présente page de téléchargement a été vue 732 fois depuis l'envoi du fichier
- Page de téléchargement
-
Aperçu du fichier
#!/usr/bin/env python
import os, sys, time, urllib.request
from sys import *
path_conf = "/etc/pacman-mirrors.conf"
arch = os.uname().machine
try :
fi = open(path_conf, "r")
except :
print("Cannot open file", path_conf)
exit(1)
while 1 :
line = fi.readline()
if line == "" :
break
line.strip()
if line == "" :
break
if line[0] == '#' or line[0] == '\n' :
continue
i = line.find("=")
if i == -1 :
continue
snom = line[0:i]
i = i + 1
j = len(line) -1
if line[i] == '"' :
i = i + 1
if line[j -1] == '"' :
j = j - 1
sval = line[i:j]
if snom == "Branch" :
branch=sval
elif snom == "MirrorlistsDir" :
pathMirrors = sval + "/"
try :
os.chdir(pathMirrors)
except :
print("Cannot change directory to", pathMirrors)
exit(1)
listeDir = os.listdir(pathMirrors)
listeDir.sort()
listeSer=[]
for i in listeDir :
print(i)
fi = open(i, "r")
while 1 :
s = fi.readline()
if s == '' :
break
if s[0] != 'S' :
continue
# print("Trace =", s)
j = s.find("$branch")
# url = s[9:j] + branch + "/core/" # + arch + "/core.db"
url = s[9:j] + "/state"
print(url)
start = time.time()
# print("start =", start)
try :
resp = urllib.request.urlopen(url, timeout=1).read()
d = resp.find(b"date=")
s = resp[d+5:].decode('utf-8')
t = s.find("T")
date = s[0:t]
heure = s[t+1:-1]
print(date, heure)
# print(time.time())
except :
print("ERROR")
elapsed = round((time.time() - start), 3)
print("elapsed", elapsed)
# break
fi.close()
#print("Fin du programme")
Partager le fichier
Télécharger pamir.py