Skip to content

Instantly share code, notes, and snippets.

@pakdev
Last active August 26, 2021 12:03
Show Gist options
  • Select an option

  • Save pakdev/f5a21d108329ebeb8e72 to your computer and use it in GitHub Desktop.

Select an option

Save pakdev/f5a21d108329ebeb8e72 to your computer and use it in GitHub Desktop.

Revisions

  1. pakdev revised this gist Dec 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion copyright.py
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@
    # The first part is any text that appears before either 'using' or
    # 'namespace' - perhaps an old copyright. The second part *should* be
    # the actual code beginning with 'using' or 'namespace'.
    match = re.search(r"^.+?((using|namespace).+)$", contents, re.DOTALL)
    match = re.search(r"^.*?((using|namespace|/\*|#).+)$", contents, re.DOTALL)
    if match:
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
  2. pakdev revised this gist Oct 30, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion copyright.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    # -*- coding: utf-8 -*-
    import os
    import re
    import codecs
    import fnmatch
    import argparse
    from textwrap import dedent
  3. pakdev revised this gist Oct 30, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions copyright.py
    Original file line number Diff line number Diff line change
    @@ -14,13 +14,13 @@
    # Descend into the 'root' directory and find all *.cs files
    files = []
    for root, dirnames, filenames in os.walk(args.root[0]):
    for filename in fnmatch.filter(filenames, "*.cs"):
    for filename in fnmatch.filter(filenames, "*.cs"):
    files.append(os.path.join(root, filename))
    print "Found {0} *.cs files".format(len(files))

    for filepath in files:
    with open(filepath) as f:
    contents = f.read()
    contents = f.read()

    # This regex will separate the contents of a *.cs file into two parts.
    # The first part is any text that appears before either 'using' or
    @@ -30,14 +30,14 @@
    if match:
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
    contents = dedent('''\
    contents = dedent('''\
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    f.write(contents)
    print "Wrote new: {0}".format(filepath)
  4. pakdev revised this gist Oct 30, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions copyright.py
    Original file line number Diff line number Diff line change
    @@ -31,11 +31,11 @@
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
    contents = dedent('''\
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
  5. pakdev revised this gist Oct 30, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion copyright.py
    Original file line number Diff line number Diff line change
    @@ -39,5 +39,5 @@
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    f.write(contents)
    f.write(contents)
    print "Wrote new: {0}".format(filepath)
  6. pakdev revised this gist Oct 30, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions copyright.py
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,11 @@
    for root, dirnames, filenames in os.walk(args.root[0]):
    for filename in fnmatch.filter(filenames, "*.cs"):
    files.append(os.path.join(root, filename))

    print "Found {0} *.cs files".format(len(files))

    for filepath in files:
    with open(filepath) as f:
    contents = f.read()
    with open(filepath) as f:
    contents = f.read()

    # This regex will separate the contents of a *.cs file into two parts.
    # The first part is any text that appears before either 'using' or
  7. pakdev revised this gist Oct 30, 2014. 1 changed file with 23 additions and 23 deletions.
    46 changes: 23 additions & 23 deletions copyright.py
    Original file line number Diff line number Diff line change
    @@ -5,40 +5,40 @@
    import fnmatch
    import argparse
    from textwrap import dedent


    parser = argparse.ArgumentParser(description='Add/update copyright on C# files')
    parser.add_argument('root', nargs=1, help='Path to the root of the C# project')
    args = parser.parse_args()

    # Descend into the 'root' directory and find all *.cs files
    files = []
    for root, dirnames, filenames in os.walk(args.root[0]):
    for filename in fnmatch.filter(filenames, "*.cs"):
    files.append(os.path.join(root, filename))

    print "Found {0} *.cs files".format(len(files))

    for filepath in files:
    with open(filepath) as f:
    contents = f.read()

    # This regex will separate the contents of a *.cs file into two parts.
    # The first part is any text that appears before either 'using' or
    # 'namespace' - perhaps an old copyright. The second part *should* be
    # The first part is any text that appears before either 'using' or
    # 'namespace' - perhaps an old copyright. The second part *should* be
    # the actual code beginning with 'using' or 'namespace'.
    match = re.search(r"^.+?((using|namespace).+)$", contents, re.DOTALL)
    if match:
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
    contents = dedent('''\
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    f.write(contents)
    print "Wrote new: {0}".format(filepath)
    match = re.search(r"^.+?((using|namespace).+)$", contents, re.DOTALL)
    if match:
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
    contents = dedent('''\
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    f.write(contents)
    print "Wrote new: {0}".format(filepath)
  8. pakdev created this gist Oct 30, 2014.
    44 changes: 44 additions & 0 deletions copyright.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    # -*- coding: utf-8 -*-
    import os
    import re
    import codecs
    import fnmatch
    import argparse
    from textwrap import dedent


    parser = argparse.ArgumentParser(description='Add/update copyright on C# files')
    parser.add_argument('root', nargs=1, help='Path to the root of the C# project')
    args = parser.parse_args()

    # Descend into the 'root' directory and find all *.cs files
    files = []
    for root, dirnames, filenames in os.walk(args.root[0]):
    for filename in fnmatch.filter(filenames, "*.cs"):
    files.append(os.path.join(root, filename))

    print "Found {0} *.cs files".format(len(files))

    for filepath in files:
    with open(filepath) as f:
    contents = f.read()

    # This regex will separate the contents of a *.cs file into two parts.
    # The first part is any text that appears before either 'using' or
    # 'namespace' - perhaps an old copyright. The second part *should* be
    # the actual code beginning with 'using' or 'namespace'.
    match = re.search(r"^.+?((using|namespace).+)$", contents, re.DOTALL)
    if match:
    # Make the file's now contain the user defined copyright (below)
    # followed by a blank line followed by the actual code.
    contents = dedent('''\
    // ****************************************************************************
    // <copyright file="{0}" company="Insert Company Here">
    // Copyright © Insert Company Here 2014
    // </copyright>
    // ****************************************************************************
    ''').format(os.path.basename(filepath)) + match.group(1)
    with open(filepath, 'w') as f:
    f.write(contents)
    print "Wrote new: {0}".format(filepath)