daca2: use ls-lR file

This commit is contained in:
Daniel Marjamäki 2013-10-24 18:22:15 +02:00
parent fc9998e439
commit ab2864e1cb
1 changed files with 21 additions and 32 deletions

View File

@ -6,51 +6,40 @@
# 4. Optional: tweak FTPSERVER and FTPPATH in this script below. # 4. Optional: tweak FTPSERVER and FTPPATH in this script below.
# 5. Run the daca2 script: python daca2.py FOLDER # 5. Run the daca2 script: python daca2.py FOLDER
import ftplib
import subprocess import subprocess
import sys import sys
import shutil import shutil
import glob import glob
import os import os
import socket
import datetime import datetime
import time import time
FTPSERVER = 'ftp.sunet.se' FTPSERVER = 'ftp.sunet.se'
FTPPATH = '/pub/Linux/distributions/Debian/debian/pool/main/' FTPPATH = '/pub/Linux/distributions/Debian/debian/'
def getpackages(folder): def getpackages(folder):
print('Connect') subprocess.call(
f = ftplib.FTP(FTPSERVER) ['nice', 'wget', 'ftp://' + FTPSERVER + FTPPATH + 'ls-lR.gz'])
f.login() subprocess.call(['nice', 'gunzip', 'ls-lR.gz'])
f = open('ls-lR', 'rt')
print('Get package list in folder ' + folder) lines = f.readlines()
packages = f.nlst(FTPPATH + folder) f.close()
subprocess.call(['rm', 'ls-lR'])
path = None
archives = [] archives = []
for package in packages:
print(package)
filename = None filename = None
path = FTPPATH + folder + '/' + package for line in lines:
if len(line) < 4:
time.sleep(1) if filename:
files = f.nlst(path) archives.append(path + '/' + filename)
path = None
for s in files: filename = None
if s.find('.orig.tar.') > 0: elif line[:13 + len(folder)] == './pool/main/' + folder + '/':
filename = s path = line[2:-2]
elif path and line.find('.orig.tar.') > 0:
if not filename: filename = line[1 + line.rfind(' '):]
for s in files:
if s.find('.tar.') > 0:
filename = s
if not filename:
archives = []
return archives
archives.append(package + '/' + filename)
return archives return archives
@ -205,7 +194,7 @@ try:
# remove all files/folders except results.txt # remove all files/folders except results.txt
removeAllExceptResults() removeAllExceptResults()
scanarchive('ftp://' + FTPSERVER + FTPPATH + FOLDER + '/' + archive) scanarchive('ftp://' + FTPSERVER + FTPPATH + archive)
except EOFError: except EOFError:
pass pass