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
|
#!/usr/bin/python3
from lintian_brush.fixer import (
report_result,
opinionated,
package_is_native,
LintianIssue,
is_debcargo_package,
meets_minimum_certainty,
warn,
)
import os
import sys
if is_debcargo_package():
sys.exit(0)
description = None
if not os.path.exists('debian/source/format'):
orig_format = None
format = '1.0'
missing_source_format_issue = LintianIssue(
'source', 'missing-debian-source-format')
if not missing_source_format_issue.should_fix():
sys.exit(0)
missing_source_format_issue.report_fixed()
description = "Explicitly specify source format."
else:
with open('debian/source/format') as f:
format = orig_format = f.read().strip()
if orig_format not in (None, '1.0'):
sys.exit(0)
older_source_format_issue = LintianIssue(
'source', 'older-source-format', info=(orig_format or '1.0'))
if older_source_format_issue.should_fix():
if package_is_native():
format = '3.0 (native)'
description = "Upgrade to newer source format %s." % format
else:
from lintian_brush.patches import (
tree_non_patches_changes,
find_patches_directory,
)
from breezy import errors
from breezy.workingtree import WorkingTree
patches_directory = find_patches_directory('.')
if patches_directory not in ('debian/patches', None):
# Non-standard patches directory.
warn(
'Tree has non-standard patches directory %s.' % (
patches_directory))
else:
try:
tree, path = WorkingTree.open_containing('.')
except errors.NotBranchError as e:
if not meets_minimum_certainty('possible'):
warn('unable to open vcs to check for delta: %s' % e)
sys.exit(0)
format = "3.0 (quilt)"
description = "Upgrade to newer source format %s." % format
else:
delta = list(tree_non_patches_changes(tree, patches_directory))
if delta:
warn('Tree has non-quilt changes against upstream.')
if opinionated():
format = "3.0 (quilt)"
description = (
"Upgrade to newer source format %s." % format)
try:
with open('debian/source/options') as f:
options = list(f.readlines())
except FileNotFoundError:
options = []
if 'single-debian-patch\n' not in options:
options.append('single-debian-patch\n')
description = description.rstrip('.') + (
', enabling single-debian-patch.')
if 'auto-commit\n' not in options:
options.append('auto-commit\n')
with open('debian/source/options', 'w') as f:
f.writelines(options)
else:
format = "3.0 (quilt)"
description = "Upgrade to newer source format %s." % format
if not os.path.exists('debian/source'):
os.mkdir('debian/source')
with open('debian/source/format', 'w') as f:
f.write('%s\n' % format)
if format != '1.0':
older_source_format_issue.report_fixed()
report_result(description=description)
|