3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 # You can obtain one at http://mozilla.org/MPL/2.0/.
8 List mozbase package dependencies or generate changelogs
12 from __future__
import absolute_import
, print_function
14 from collections
import Iterable
15 from distutils
.version
import StrictVersion
21 import setup_development
23 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
28 if not isinstance(command
, Iterable
):
29 command
= command
.split()
30 command
.insert(0, 'hg')
32 output
= subprocess
.check_output(command
, cwd
=here
)
33 except subprocess
.CalledProcessError
:
39 setup
= os
.path
.join(args
.module
, 'setup.py')
41 def get_version_rev(v
=None):
42 revisions
= run_hg(['log', setup
, '--template={rev},']).split(',')[:-1]
44 diff
= run_hg(['diff', '-c', rev
, setup
, '-U0'])
47 for line
in diff
.splitlines():
48 if line
.startswith('-PACKAGE_VERSION'):
50 minus_version
= StrictVersion(line
.split()[-1].strip('"\''))
53 elif line
.startswith('+PACKAGE_VERSION'):
55 plus_version
= StrictVersion(line
.split()[-1].strip('"\''))
59 # make sure the change isn't a backout
60 if not minus_version
or plus_version
> minus_version
:
64 if StrictVersion(v
) == plus_version
:
67 print("Could not find %s revision for version %s." % (args
.module
, v
or 'latest'))
70 from_ref
= args
.from_ref
or get_version_rev()
71 to_ref
= args
.to_ref
or 'tip'
74 from_ref
= get_version_rev(from_ref
)
76 to_ref
= get_version_rev(to_ref
)
78 delim
= '\x12\x59\x52\x99\x05'
79 changelog
= run_hg(['log', '-r', '%s:children(%s)' % (to_ref
, from_ref
),
80 '--template={desc}%s' % delim
,
81 '-M', args
.module
]).split(delim
)[:-1]
84 lines
= desc
.splitlines()
85 lines
= [('* %s' if i
== 0 else ' %s') % l
for i
, l
in enumerate(lines
)]
86 return '\n'.join(lines
)
88 changelog
= map(prettify
, changelog
)
89 print('\n'.join(changelog
))
92 def dependencies(args
):
93 # get package information
96 for package
in setup_development
.mozbase_packages
:
97 directory
= os
.path
.join(setup_development
.here
, package
)
98 info
[directory
] = setup_development
.info(directory
)
99 name
, _dependencies
= setup_development
.get_dependencies(directory
)
100 assert name
== info
[directory
]['Name']
101 dependencies
[name
] = _dependencies
103 # print package version information
104 for value
in info
.values():
105 print('%s %s : %s' % (value
['Name'], value
['Version'],
106 ', '.join(dependencies
[value
['Name']])))
109 def main(args
=sys
.argv
[1:]):
110 parser
= argparse
.ArgumentParser()
111 subcommands
= parser
.add_subparsers(help="Sub-commands")
113 p_deps
= subcommands
.add_parser('dependencies', help="Print dependencies.")
114 p_deps
.set_defaults(func
=dependencies
)
116 p_changelog
= subcommands
.add_parser('changelog', help="Print a changelog.")
117 p_changelog
.add_argument('module', help="Module to get changelog from.")
118 p_changelog
.add_argument('--from', dest
='from_ref', default
=None,
119 help="Starting version or revision to list "
120 "changes from. [defaults to latest version]")
121 p_changelog
.add_argument('--to', dest
='to_ref', default
=None,
122 help="Ending version or revision to list "
123 "changes to. [defaults to tip]")
124 p_changelog
.set_defaults(func
=changelog
)
126 # default to showing dependencies
128 args
.append('dependencies')
129 args
= parser
.parse_args(args
)
133 if __name__
== '__main__':