1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

# Copyright 2013-2018 The Distro Tracker Developers 

# See the COPYRIGHT file at the top-level directory of this distribution and 

# at https://deb.li/DTAuthors 

# 

# This file is part of Distro Tracker. It is subject to the license terms 

# in the LICENSE file found in the top-level directory of this 

# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

# including this file, may be copied, modified, propagated, or distributed 

# except according to the terms contained in the LICENSE file. 

"""Utilities for processing Debian package information.""" 

import os 

import re 

import shutil 

import subprocess 

import tarfile 

 

import apt 

 

import apt_pkg 

 

from debian import deb822 

 

from django.conf import settings 

from django.urls import reverse 

from django.utils.encoding import force_bytes 

 

from distro_tracker.core.utils.email_messages import \ 

name_and_address_from_string as parse_address 

from distro_tracker.core.utils.email_messages import \ 

names_and_addresses_from_string as parse_addresses 

 

 

def package_hashdir(package_name): 

""" 

Returns the name of the hash directory used to avoid having too 

many entries in a single directory. It's usually the first letter 

of the package except for lib* packages where it's the first 4 

letters. 

 

:param package_name: The package name. 

:type package_name: str 

 

:returns: Name of the hash directory. 

:rtype: str 

""" 

if package_name is None: 

return None 

if package_name.startswith('lib'): 

return package_name[0:4] 

else: 

return package_name[0:1] 

 

 

def package_url(package_name): 

""" 

Returns the URL of the page dedicated to this package name. 

 

:param package_name: The package name. 

:type package_name: str or PackageName model 

 

:returns: Name of the hash directory. 

:rtype: str 

""" 

if package_name is None: 

return None 

return reverse('dtracker-package-page', 

kwargs={'package_name': str(package_name)}) 

 

 

def extract_vcs_information(stanza): 

""" 

Extracts the VCS information from a package's Sources entry. 

 

:param stanza: The ``Sources`` entry from which to extract the VCS info. 

Maps ``Sources`` key names to values. 

:type stanza: dict 

 

:returns: VCS information regarding the package. Contains the following 

keys: type[, browser, url, branch] 

:rtype: dict 

""" 

vcs = {} 

for key, value in stanza.items(): 

key = key.lower() 

if key == 'vcs-browser': 

vcs['browser'] = value 

elif key.startswith('vcs-'): 

vcs['type'] = key[4:] 

vcs['url'] = value 

if vcs['type'] == 'git': 

match = re.match(r'(?P<url>.*?)\s+-b\s*(?P<branch>\S+)', value) 

if match: 

vcs['url'] = match.group('url') 

vcs['branch'] = match.group('branch') 

return vcs 

 

 

def extract_dsc_file_name(stanza): 

""" 

Extracts the name of the .dsc file from a package's Sources entry. 

 

:param stanza: The ``Sources`` entry from which to extract the VCS info. 

Maps ``Sources`` key names to values. 

:type stanza: dict 

 

""" 

for field in ('checksums-sha256', 'checksums-sha1', 'files'): 

for entry in stanza.get(field, []): 

109 ↛ 108line 109 didn't jump to line 108, because the condition on line 109 was never false if entry.get('name', '').endswith('.dsc'): 

return entry['name'] 

 

return None 

 

 

def extract_information_from_sources_entry(stanza): 

""" 

Extracts information from a ``Sources`` file entry and returns it in the 

form of a dictionary. 

 

:param stanza: The raw entry's key-value pairs. 

:type stanza: Case-insensitive dict 

""" 

binaries = [ 

binary.strip() 

for binary in stanza['binary'].split(',') 

] 

entry = { 

'version': stanza['version'], 

'homepage': stanza.get('homepage', ''), 

'priority': stanza.get('priority', ''), 

'section': stanza.get('section', ''), 

'architectures': stanza['architecture'].split(), 

'binary_packages': binaries, 

'maintainer': parse_address(stanza['maintainer']), 

'uploaders': parse_addresses(stanza.get('uploaders', '')), 

'standards_version': stanza.get('standards-version', ''), 

'vcs': extract_vcs_information(stanza), 

'dsc_file_name': extract_dsc_file_name(stanza), 

'directory': stanza.get('directory', ''), 

} 

 

return entry 

 

 

def extract_information_from_packages_entry(stanza): 

""" 

Extracts information from a ``Packages`` file entry and returns it in the 

form of a dictionary. 

 

:param stanza: The raw entry's key-value pairs. 

:type stanza: Case-insensitive dict 

""" 

entry = { 

'version': stanza['version'], 

'short_description': stanza.get('description', '')[:300], 

} 

 

return entry 

 

 

class SourcePackageRetrieveError(Exception): 

pass 

 

 

class AptCache(object): 

""" 

A class for handling cached package information. 

""" 

DEFAULT_MAX_SIZE = 1 * 1024 ** 3 # 1 GiB 

QUILT_FORMAT = '3.0 (quilt)' 

 

class AcquireProgress(apt.progress.base.AcquireProgress): 

""" 

Instances of this class can be passed to :meth:`apt.cache.Cache.update` 

calls. 

It provides a way to track which files were changed and which were not 

by an update operation. 

""" 

def __init__(self, *args, **kwargs): 

super(AptCache.AcquireProgress, self).__init__(*args, **kwargs) 

self.fetched = [] 

self.hit = [] 

 

def done(self, item): 

self.fetched.append(os.path.split(item.owner.destfile)[1]) 

 

def ims_hit(self, item): 

self.hit.append(os.path.split(item.owner.destfile)[1]) 

 

def pulse(self, owner): 

return True 

 

def __init__(self): 

# The root cache directory is a subdirectory in the 

# DISTRO_TRACKER_CACHE_DIRECTORY 

self.cache_root_dir = os.path.join( 

settings.DISTRO_TRACKER_CACHE_DIRECTORY, 

'apt-cache' 

) 

self.sources_list_path = os.path.join( 

self.cache_root_dir, 'etc', 'sources.list') 

self.conf_file_path = os.path.join(self.cache_root_dir, 

'etc', 'apt.conf') 

os.environ['APT_CONFIG'] = self.conf_file_path 

 

self.sources = [] 

self.packages = [] 

self.cache_max_size = getattr( 

settings, 'DISTRO_TRACKER_APT_CACHE_MAX_SIZE', 

self.DEFAULT_MAX_SIZE) 

#: The directory where source package files are cached 

self.source_cache_directory = os.path.join(self.cache_root_dir, 

'packages') 

self._cache_size = None # Evaluate the cache size lazily 

 

self.configure_cache() 

 

@property 

def cache_size(self): 

if self._cache_size is None: 

self._cache_size = \ 

self.get_directory_size(self.source_cache_directory) 

return self._cache_size 

 

def get_directory_size(self, directory_path): 

""" 

Returns the total space taken by the given directory in bytes. 

 

:param directory_path: The path to the directory 

:type directory_path: string 

 

:rtype: int 

""" 

# Convert the directory path to bytes to make sure all os calls deal 

# with bytes, not unicode objects. 

# This way any file names with invalid utf-8 names, are correctly 

# handled, without causing an error. 

directory_path = force_bytes(directory_path) 

total_size = 0 

for dirpath, dirnames, filenames in os.walk(directory_path): 

for file_name in filenames: 

file_path = os.path.join(dirpath, file_name) 

stat = os.lstat(file_path) 

total_size += stat.st_size 

 

return total_size 

 

def clear_cache(self): 

""" 

Removes all cache information. This causes the next update to retrieve 

fresh repository files. 

""" 

self._remove_dir(self.cache_root_dir) 

self.configure_cache() 

 

def update_sources_list(self): 

""" 

Updates the ``sources.list`` file used to list repositories for which 

package information should be cached. 

""" 

from distro_tracker.core.models import Repository 

 

directory = os.path.dirname(self.sources_list_path) 

if not os.path.exists(directory): 

os.makedirs(directory) 

 

with open(self.sources_list_path, 'w') as sources_list: 

for repository in Repository.objects.all(): 

sources_list.write(repository.sources_list_entry + '\n') 

 

def update_apt_conf(self): 

""" 

Updates the ``apt.conf`` file which gives general settings for the 

:class:`apt.cache.Cache`. 

 

In particular, this updates the list of all architectures which should 

be considered in package updates based on architectures that the 

repositories support. 

""" 

from distro_tracker.core.models import Architecture 

 

with open(self.conf_file_path, 'w') as conf_file: 

conf_file.write('APT::Architectures { ') 

for architecture in Architecture.objects.all(): 

conf_file.write('"{arch}"; '.format(arch=architecture)) 

conf_file.write('};\n') 

conf_file.write('Acquire::CompressionTypes::Order:: "xz";\n') 

conf_file.write('Dir "{}/";\n'.format(self.cache_root_dir)) 

conf_file.write('Dir::State "state/";\n') 

conf_file.write('Dir::State::status "dpkg-status";\n') 

conf_file.write('Dir::Etc "etc/";\n') 

conf_file.write('Dir::Etc::sourcelist "{src}";\n'.format( 

src=self.sources_list_path)) 

conf_file.write('Dir::Etc::Trusted "{src}";\n'.format( 

src=settings.DISTRO_TRACKER_TRUSTED_GPG_MAIN_FILE)) 

conf_file.write('Dir::Etc::TrustedParts "{src}";\n'.format( 

src=settings.DISTRO_TRACKER_TRUSTED_GPG_PARTS_DIR)) 

 

def configure_cache(self): 

""" 

Configures the cache based on the most current repository information. 

""" 

self.update_sources_list() 

self.update_apt_conf() 

# Clean up the configuration we might have read during "import apt" 

for root_key in apt_pkg.config.list(): 

apt_pkg.config.clear(root_key) 

# Load the proper configuration 

apt_pkg.init() 

# Ensure we have the required directories 

for apt_dir in [apt_pkg.config.find_dir('Dir::State::lists'), 

apt_pkg.config.find_dir('Dir::Etc::sourceparts'), 

apt_pkg.config.find_dir('Dir::Cache::archives')]: 

if not os.path.exists(apt_dir): 

os.makedirs(apt_dir) 

 

def _index_file_full_path(self, file_name): 

""" 

Returns the absolute path for the given cached index file. 

 

:param file_name: The name of the cached index file. 

:type file_name: string 

 

:rtype: string 

""" 

return os.path.join( 

apt_pkg.config.find_dir('Dir::State::lists'), 

file_name 

) 

 

def _match_index_file_to_repository(self, sources_file): 

""" 

Returns a two-tuple ``(class:`Repository <distro_tracker.core. 

models.Repository>`, component)``. The class:`Repository 

<distro_tracker.core.models.Repository>` instance which matches the 

given cached ``Sources`` file and the ``component`` of the ``Source``. 

 

:rtype: (:class:`Repository <distro_tracker.core.models.Repository>`, 

string) 

""" 

from distro_tracker.core.models import Repository 

 

sources_list = apt_pkg.SourceList() 

sources_list.read_main_list() 

component_url = None 

component = None 

for entry in sources_list.list: 

for index_file in entry.index_files: 

if os.path.basename(sources_file) in index_file.describe: 

base_url, component, _ = index_file.describe.split(None, 2) 

base_url = base_url.rstrip('/') 

component_url = base_url + '/' + component 

break 

 

components = component.split('/') 

if len(components) >= 2: 

component = components[1].strip() 

 

for repository in Repository.objects.all(): 

if component_url in repository.component_urls: 

return repository, component 

 

def _get_all_cached_files(self): 

""" 

Returns a list of all cached files. 

""" 

lists_directory = apt_pkg.config.find_dir('Dir::State::lists') 

try: 

return [ 

os.path.join(lists_directory, file_name) 

for file_name in os.listdir(lists_directory) 

if os.path.isfile(os.path.join(lists_directory, file_name)) 

] 

except OSError: 

# The directory structure does not exist => nothing is cached 

return [] 

 

def get_cached_files(self, filter_function=None): 

""" 

Returns cached files, optionally filtered by the given 

``filter_function`` 

 

:param filter_function: Takes a file name as the only parameter and 

returns a :class:`bool` indicating whether it should be included 

in the result. 

:type filter_function: callable 

 

:returns: A list of cached file names 

:rtype: list 

""" 

391 ↛ 393line 391 didn't jump to line 393, because the condition on line 391 was never true if filter_function is None: 

# Include all files if the filter function is not provided 

def filter_function(x): 

return True 

 

return [ 

file_name 

for file_name in self._get_all_cached_files() 

if filter_function(file_name) 

] 

 

def get_sources_files_for_repository(self, repository): 

""" 

Returns all ``Sources`` files which are cached for the given 

repository. 

 

For instance, ``Sources`` files for different suites are cached 

separately. 

 

:param repository: The repository for which to return all cached 

``Sources`` files 

:type repository: :class:`Repository 

<distro_tracker.core.models.Repository>` 

 

:rtype: ``iterable`` of strings 

""" 

return self.get_cached_files( 

lambda file_name: ( 

file_name.endswith('Sources') and 

self._match_index_file_to_repository( 

file_name)[0] == repository)) 

 

def get_packages_files_for_repository(self, repository): 

""" 

Returns all ``Packages`` files which are cached for the given 

repository. 

 

For instance, ``Packages`` files for different suites are cached 

separately. 

 

:param repository: The repository for which to return all cached 

``Packages`` files 

:type repository: :class:`Repository 

<distro_tracker.core.models.Repository>` 

 

:rtype: ``iterable`` of strings 

""" 

return self.get_cached_files( 

lambda file_name: ( 

file_name.endswith('Packages') and 

self._match_index_file_to_repository( 

file_name)[0] == repository)) 

 

def update_repositories(self, force_download=False): 

""" 

Initiates a cache update. 

 

:param force_download: If set to ``True`` causes the cache to be 

cleared before starting the update, thus making sure all index 

files are downloaded again. 

 

:returns: A two-tuple ``(updated_sources, updated_packages)``. Each of 

the tuple's members is a list of 

(:class:`Repository <distro_tracker.core.models.Repository>`, 

``component``, ``file_name``) tuple representing the repository 

which was updated, component, and the file which contains the fresh 

information. The file is either a ``Sources`` or a ``Packages`` 

file respectively. 

""" 

if force_download: 

self.clear_cache() 

 

self.configure_cache() 

 

cache = apt.Cache(rootdir=self.cache_root_dir) 

progress = AptCache.AcquireProgress() 

cache.update(progress) 

 

updated_sources = [] 

updated_packages = [] 

for fetched_file in progress.fetched: 

if fetched_file.endswith('Sources'): 

dest = updated_sources 

elif fetched_file.endswith('Packages'): 

dest = updated_packages 

else: 

continue 

repository, component = self._match_index_file_to_repository( 

fetched_file) 

dest.append(( 

repository, component, self._index_file_full_path(fetched_file) 

)) 

 

return updated_sources, updated_packages 

 

def _get_format(self, record): 

""" 

Returns the Format field value of the given source package record. 

""" 

record = deb822.Deb822(record) 

return record['format'] 

 

def _extract_quilt_package_debian_tar(self, debian_tar_path, outdir): 

""" 

Extracts the given tarball to the given output directory. 

""" 

with tarfile.open(debian_tar_path) as archive_file: 

archive_file.extractall(outdir) 

 

def get_package_source_cache_directory(self, package_name): 

""" 

Returns the path to the directory where a particular source package is 

cached. 

 

:param package_name: The name of the source package 

:type package_name: string 

 

:rtype: string 

""" 

package_hash = ( 

package_name[0] 

if not package_name.startswith('lib') else 

package_name[:4] 

) 

return os.path.join( 

self.source_cache_directory, 

package_hash, 

package_name) 

 

def get_source_version_cache_directory(self, package_name, version): 

""" 

Returns the path to the directory where a particular source package 

version files are extracted. 

 

:param package_name: The name of the source package 

:type package_name: string 

 

:param version: The version of the source package 

:type version: string 

 

:rtype: string 

""" 

package_dir = self.get_package_source_cache_directory(package_name) 

return os.path.join(package_dir, package_name + '-' + version) 

 

def _remove_dir(self, directory_path): 

""" 

Removes the given directory, including any subdirectories and files. 

The method makes sure to correctly handle the situation where the 

directory contains files with names which are invalid utf-8. 

""" 

# Convert the directory path to bytes to make sure all os calls deal 

# with bytes, not unicode objects. 

# This way any file names with invalid utf-8 names, are correctly 

# handled, without causing an error. 

directory_path = force_bytes(directory_path) 

if os.path.exists(directory_path): 

shutil.rmtree(directory_path) 

 

def clear_cached_sources(self): 

""" 

Clears all cached package source files. 

""" 

self._remove_dir(self.source_cache_directory) 

self._cache_size = self.get_directory_size(self.source_cache_directory) 

 

def _get_apt_source_records(self, source_name, version): 

""" 

Returns a :class:`apt_pkg.SourceRecords` instance where the given 

source package is the current working record. 

""" 

apt.Cache(rootdir=self.cache_root_dir) # must be pre-created 

source_records = apt_pkg.SourceRecords() 

source_records.restart() 

# Find the cached record matching this source package and version 

found = False 

while source_records.lookup(source_name): 

if source_records.version == version: 

found = True 

break 

 

if not found: 

# Package version does not exist in the cache 

raise SourcePackageRetrieveError( 

"Could not retrieve package {pkg} version {ver}:" 

" No such version found in the cache".format( 

pkg=source_name, ver=version)) 

 

return source_records 

 

def _extract_dpkg_source(self, retrieved_files, outdir): 

""" 

Uses dpkg-source to extract the source package. 

""" 

dsc_file_path = next( 

file_path 

for file_path in retrieved_files 

if file_path.endswith('.dsc')) 

dsc_file_path = os.path.abspath(dsc_file_path) 

outdir = os.path.abspath(outdir) 

subprocess.check_output(["dpkg-source", "-x", dsc_file_path, outdir], 

stderr=subprocess.STDOUT) 

 

def _apt_acquire_package(self, 

source_records, 

dest_dir_path, 

debian_directory_only): 

""" 

Using :class:`apt_pkg.Acquire`, retrieves the source files for the 

source package described by the current source_records record. 

 

:param source_records: The record describing the source package whose 

files should be retrieved. 

:type source_records: :class:`apt_pkg.Acquire` 

 

:param dest_dir_path: The path to the directory where the downloaded 

files should be saved. 

:type dest_dir_path: string 

 

:param debian_directory_only: A flag indicating whether only the debian 

directory should be downloaded. 

 

:returns: A list of absolute paths of all retrieved source files. 

:rtype: list of strings 

""" 

package_format = self._get_format(source_records.record) 

# A reference to each AcquireFile instance must be kept 

files = [] 

acquire = apt_pkg.Acquire(apt.progress.base.AcquireProgress()) 

for md5, size, path, file_type in source_records.files: 

base = os.path.basename(path) 

dest_file_path = os.path.join(dest_dir_path, base) 

if debian_directory_only and package_format == self.QUILT_FORMAT: 

if file_type != 'diff': 

# Only retrieve the .debian.tar.* file for quilt packages 

# when only the debian directory is wanted 

continue 

files.append(apt_pkg.AcquireFile( 

acquire, 

source_records.index.archive_uri(path), 

md5, 

size, 

base, 

destfile=dest_file_path 

)) 

 

acquire.run() 

 

# Check if all items are correctly retrieved and build the list of file 

# paths. 

retrieved_paths = [] 

for item in acquire.items: 

if item.status != item.STAT_DONE: 

raise SourcePackageRetrieveError( 

'Could not retrieve file {file}: {error}'.format( 

file=item.destfile, 

error=item.error_text.decode('utf-8'))) 

retrieved_paths.append(item.destfile) 

 

return retrieved_paths 

 

def retrieve_source(self, source_name, version, 

debian_directory_only=False): 

""" 

Retrieve the source package files for the given source package version. 

 

:param source_name: The name of the source package 

:type source_name: string 

:param version: The version of the source package 

:type version: string 

:param debian_directory_only: Flag indicating if the method should try 

to retrieve only the debian directory of the source package. This 

is usually only possible when the package format is 3.0 (quilt). 

:type debian_directory_only: Boolean 

 

:returns: The path to the directory containing the extracted source 

package files. 

:rtype: string 

""" 

if self.cache_size > self.cache_max_size: 

# If the maximum allowed cache size has been exceeded, 

# clear the cache 

self.clear_cached_sources() 

 

source_records = self._get_apt_source_records(source_name, version) 

 

dest_dir_path = self.get_package_source_cache_directory(source_name) 

678 ↛ 681line 678 didn't jump to line 681, because the condition on line 678 was never false if not os.path.exists(dest_dir_path): 

os.makedirs(dest_dir_path) 

# Remember the size of the directory in the beginning 

old_size = self.get_directory_size(dest_dir_path) 

 

# Download the source files 

retrieved_files = self._apt_acquire_package( 

source_records, dest_dir_path, debian_directory_only) 

 

# Extract the retrieved source files 

outdir = self.get_source_version_cache_directory(source_name, version) 

# dpkg-source expects this directory not to exist 

self._remove_dir(outdir) 

 

package_format = self._get_format(source_records.record) 

693 ↛ 695line 693 didn't jump to line 695, because the condition on line 693 was never true if debian_directory_only and package_format == self.QUILT_FORMAT: 

# dpkg-source cannot extract an incomplete package 

self._extract_quilt_package_debian_tar(retrieved_files[0], outdir) 

else: 

# Let dpkg-source handle the extraction in all other cases 

self._extract_dpkg_source(retrieved_files, outdir) 

 

# Update the current cache size based on the changes made by getting 

# this source package. 

new_size = self.get_directory_size(dest_dir_path) 

size_delta = new_size - old_size 

self._cache_size += size_delta 

 

return outdir 

 

 

def html_package_list(packages): 

"""Return a HTML-formatted list of packages.""" 

packages_html = [] 

for package in packages: 

if "/" in package: 

(source_package_name, remain) = package.split("/", 1) 

remain = "/%s" % (remain,) 

else: 

(source_package_name, remain) = (package, "") 

html = '<a href="{}">{}</a>{}'.format( 

package_url(source_package_name), source_package_name, remain) 

packages_html.append(html) 

 

return ', '.join(packages_html)