license-header-tool 0.0.1 documentation

Welcome to license-header-tool’s documentation!

Contents

Welcome to license-header-tool’s documentation!

Contents:

Simple usage

  1. Adjust the conf.ini file to meet your needs.

  2. ensure the use_these_headers.py file has your deisred headers in it.

  3. run:

    python fileheadermaker.py –conf=conf.ini –fldr=/home/pbrian/myproject

We want to be able to visit file(s) on a filesystem and match their suffixes with known suffixes, and ensure that each file has an appropriate OSS license header in it.

How does it work

  1. Given a fldr, walk the tree
  2. for each file in tree, analyse it
  3. if file matches conf.ini defined set of exts, replace the header of the file with the one named “use_these_headers.py”

(Yeah I did play with importing the recipie via imp. It is feasible but PITA for doctests and generally overkill)

How to run tests

$ python licensetoollib.py
(will run doctests)
licensetoollib.adjust_one_file(f, confd)[source]

Badly named function that iterates over each line in a file fromt top and if that line meets the “hdr” criteria (ie starts with comment symbol) it is kept as original hdr, and gets replaced with new shiny hdr. Once hdr state ends everything is then kept pristine.

testing?

licensetoollib.analyse_file(f, confd)[source]

Given file, decide if it is suitable, if it alredy has header, is header uptdate and otehr

bit rubbish analysis - returning flags to act upon

licensetoollib.ext_in_list(ext, l)[source]

Just simple for in seems to break in odd places - pullingout

>>> ext_in_list(".py", [".py", ".js", ".java"])
True
>>> ext_in_list(".rpy", [".py", ".js", ".java"])
False
licensetoollib.extract_hdr(txt, ext)[source]

Given a file return the hdr and body components

>>> txt = '''#!/bin/python
... # this is a header
...
... def foo():
...     print 1'''
>>> extract_hdr(txt, ".py")
('#!/bin/python\n# this is a header\n\n', 'def foo():\n    print 1\n')
licensetoollib.lineishdr(l, ext)[source]

Determine is a line at top of a file is a header, or if its body

We simply assume that the header of a file is a contiguous block of comment and blank lines. Anything else triggers “no longer header” flag

issue: sometimes we have lines of comment that are comment only
because previous line is this block style is parseable, but I dont want to wonder off course too much. For the moment only line by line comments are considered headers.
>>> lineishdr("#!/usr/local/bin/python", ".py")
True
>>> lineishdr("#!/usr/local/bin/python", ".rst")
False
>>> lineishdr("  ", ".py")
True
>>> lineishdr(" #!/usr/local/bin/python", ".py")
False
>>> lineishdr("import os", ".js")
False
>>> lineishdr("// THis is JS", ".js")
True
>>> lineishdr("function foo()", ".py")
False
licensetoollib.walk_tree(fldr, extlist)[source]

Given fldr, walk the tree and return all files as abspaths

Contents