Remove usage of glob

This commit is contained in:
Anders Ingemann 2013-07-07 18:07:15 +02:00
parent 6671a67d9b
commit f5a2acf128
3 changed files with 10 additions and 14 deletions

View file

@ -64,9 +64,8 @@ class AptClean(Task):
def run(self, info): def run(self, info):
log_check_call(['chroot', info.root, 'apt-get', 'clean']) log_check_call(['chroot', info.root, 'apt-get', 'clean'])
import glob lists = os.path.join(info.root, 'var/lib/apt/lists')
lists = glob.glob(os.path.join(info.root, 'var/lib/apt/lists/*')) for list_file in [os.path.join(lists, f) for f in os.listdir(lists)]:
for list_file in lists:
if os.path.isfile(list_file): if os.path.isfile(list_file):
os.remove(list_file) os.remove(list_file)

View file

@ -1,6 +1,6 @@
from base import Task from base import Task
from common import phases from common import phases
import os.path import os
class ConfigureGrub(Task): class ConfigureGrub(Task):
@ -14,10 +14,8 @@ class ConfigureGrub(Task):
stat.S_IROTH | stat.S_IXOTH) stat.S_IROTH | stat.S_IXOTH)
x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
import os grubd = os.path.join(info.root, 'etc/grub.d')
import glob for cfg in [os.path.join(grubd, f) for f in os.listdir(grubd)]:
grub2_cfgs = glob.glob(os.path.join(info.root, 'etc/grub.d/*'))
for cfg in grub2_cfgs:
os.chmod(cfg, os.stat(cfg).st_mode & ~ x_all) os.chmod(cfg, os.stat(cfg).st_mode & ~ x_all)
from shutil import copy from shutil import copy

View file

@ -34,11 +34,10 @@ class CleanTMP(Task):
phase = phases.system_cleaning phase = phases.system_cleaning
def run(self, info): def run(self, info):
import glob tmp = os.path.join(info.root, 'tmp')
tmp_files = glob.glob(os.path.join(info.root, 'tmp/*')) for tmp_file in [os.path.join(tmp, f) for f in os.listdir(tmp)]:
for tmp_file in tmp_files:
os.remove(tmp_file) os.remove(tmp_file)
log_files = glob.glob(os.path.join(info.root, 'var/log/{bootstrap,dpkg}.log')) log = os.path.join(info.root, 'var/log/')
for log_file in log_files: os.remove(os.path.join(log, 'bootstrap.log'))
os.remove(log_file) os.remove(os.path.join(log, 'dpkg.log'))