1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/mirrors-kimchi

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
scan.py 3 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Aline Manera Отправлено 02.05.2019 00:17 8334268
#
# Project Kimchi
#
# Copyright IBM Corp, 2015-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import glob
import hashlib
import os.path
import shutil
import tempfile
import time
from wok.plugins.kimchi.isoinfo import IsoImage
from wok.plugins.kimchi.isoinfo import probe_iso
from wok.utils import wok_log
SCAN_IGNORE = ['/tmp/kimchi-scan-*']
class Scanner(object):
SCAN_TTL = 300
def __init__(self, record_clean_cb):
self.clean_cb = record_clean_cb
def delete(self):
self.clean_stale(-1)
def clean_stale(self, window=SCAN_TTL):
"""
Clear scan pools generated before time window,
Clear all scan pools if window is -1.
"""
try:
now = time.time()
clean_list = glob.glob('/tmp/kimchi-scan-*')
for d in clean_list:
transient_pool = os.path.basename(
d).replace('kimchi-scan-', '')[0:-6]
if now - os.path.getmtime(d) > window:
shutil.rmtree(d)
self.clean_cb(transient_pool)
except OSError as e:
msg = f'Exception {e} occured when cleaning stale pool, ignore'
wok_log.debug(msg)
def scan_dir_prepare(self, name):
# clean stale scan storage pools
self.clean_stale()
return tempfile.mkdtemp(prefix='kimchi-scan-' + name, dir='/tmp')
def start_scan(self, cb, params):
def updater(iso_info):
iso_name = os.path.basename(iso_info['path'])[:-3]
duplicates = '%s/%s*' % (params['pool_path'], iso_name)
for f in glob.glob(duplicates):
iso_img = IsoImage(f)
if (iso_info['distro'], iso_info['version']) == iso_img.probe():
return
iso_path = (
iso_name +
hashlib.md5(iso_info['path'].encode('utf-8')).hexdigest() +
'.iso'
)
link_name = os.path.join(
params['pool_path'], os.path.basename(iso_path))
os.symlink(iso_info['path'], link_name)
ignore_paths = params.get('ignore_list', [])
scan_params = dict(
path=params['scan_path'],
updater=updater,
ignore_list=ignore_paths + SCAN_IGNORE,
)
probe_iso(None, scan_params)
cb('', True)

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/mirrors-kimchi.git
git@api.gitlife.ru:oschina-mirror/mirrors-kimchi.git
oschina-mirror
mirrors-kimchi
mirrors-kimchi
master