Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small util fixes and updated example sources #18

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions maintenance_utils/python-modernize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# https://github.com/takluyver/python-modernize
# Seems to be more maintained
# Run in root of xylem repository to update python files in such a way
# as to make maintaining portable py2/py3 code easier.
python-modernize xylem test --future-unicode
# as to make maintaining portable py2/py3 code easier. If you are happy
# with the diff, run with passing `-w` to write files
python-modernize xylem test --future-unicode $@
36 changes: 27 additions & 9 deletions maintenance_utils/update_license_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Run in root of xylem directory to add / update the license header in
# all python files

# TODO: support updating the header but retaining the year, possibly based on file edit date-time

import argparse
import os
import re
Expand Down Expand Up @@ -33,20 +35,22 @@ def process_args(args):


def replace_headers(args):

count = 0
for path in args.path:
replace_headers_recursive(path, args)
count += replace_headers_recursive(path, args)
return count


def replace_headers_recursive(path, args):
count = 0
if os.path.islink(path):
if args.verbose:
print("%s -- ignoring symbolic link" % path)
elif os.path.isfile(path):
filename = os.path.basename(path)
if args.matching.match(filename):
if not args.except_matching.match(filename):
replace_headers_file(path, args)
count += replace_headers_file(path, args)
else:
if args.verbose:
print("%s -- ignoring excluded filename" % path)
Expand All @@ -61,13 +65,15 @@ def replace_headers_recursive(path, args):
if args.verbose:
print("%s -- descending into directory" % path)
for p in os.listdir(path):
replace_headers_recursive(os.path.join(path, p), args)
count += replace_headers_recursive(os.path.join(path, p), args)
else:
if args.verbose:
print("%s -- ignoring unknown directory entry" % path)
return count


def replace_headers_file(path, args):
count = 0
content = read_file(path)
if args.except_content.search(content):
if args.verbose:
Expand All @@ -80,7 +86,8 @@ def replace_headers_file(path, args):
else:
print("%s -- replacing old header" % path)
content = content[:match.start()] + args.license_header + content[match.end():]
if not args.simulate:
count += 1
if args.write:
write_file(path, content)
else:
lines = content.splitlines(True)
Expand All @@ -93,8 +100,10 @@ def replace_headers_file(path, args):
else:
print("%s -- inserting new header at the beginning of file" % path)
insert_header(lines, 0, args.license_header)
if not args.simulate:
count += 1
if args.write:
write_file(path, "".join(lines))
return count


def insert_header(lines, index, header):
Expand Down Expand Up @@ -136,8 +145,8 @@ def main():
add("--except-content", action="append",
help="Multiline regular expression matching file content. If it \
matches, file is ignored. May be passed multiple times.")
add("--simulate", "-s", action="store_true",
help="If passed, no files are written.")
add("--write", "-w", action="store_true",
help="If not passed, no files are actually modified.")
add("--verbose", "-v", action="store_true",
help="If passed, verbose output on ignored files and folders.")

Expand All @@ -152,7 +161,16 @@ def main():

process_args(args)

replace_headers(args)
count = replace_headers(args)

if count == 0:
print("Did not need to update any files.")
else:
if args.write:
print("Updated %s files." % count)
else:
print("Would have updated %s files. Run again with `-w` to "
"actually update the files." % count)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions maintenance_utils/update_license_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Run in root of xylem repository

# When result looks ok, run again with `-w` to actually update the files

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
python "$DIR/update_license_headers.py" \
xylem test \
Expand Down
8 changes: 4 additions & 4 deletions prefix/etc/xylem/sources.d/20-default-sources.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- rules: 'file:/Users/demmeln/work/rosdistro/rosdep/osx-homebrew.yaml'
- rules: 'file:/Users/demmeln/work/rosdistro/rosdep/base.yaml'
- rules: 'file:/Users/demmeln/work/rosdistro/rosdep/python.yaml'
- rules: 'file:/Users/demmeln/work/rosdistro/rosdep/ruby.yaml'
- rules: 'https://raw.githubusercontent.com/NikolausDemmel/rosdistro/xylem/rosdep/osx-homebrew.yaml'
- rules: 'https://raw.githubusercontent.com/NikolausDemmel/rosdistro/xylem/rosdep/base.yaml'
- rules: 'https://raw.githubusercontent.com/NikolausDemmel/rosdistro/xylem/rosdep/python.yaml'
- rules: 'https://raw.githubusercontent.com/NikolausDemmel/rosdistro/xylem/rosdep/ruby.yaml'
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.