File: removeComments.py

package info (click to toggle)
azure-devops-cli-extension 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,680 kB
  • sloc: python: 160,797; xml: 198; sh: 61; makefile: 56
file content (30 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (3)
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
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os

def remove_comment_from_file(filePath):
    temp_file = filePath + ".tmp"
    file = open(filePath, "r")
    file_new = open(temp_file, "w")

    comment_in_progress = False
    for line in file:
        if "\"\"\"" in line:
            comment_in_progress = not comment_in_progress
        if not comment_in_progress and "\"\"\"" not in line and not line.startswith("#"):
            file_new.write(line)

    file.close()
    file_new.close()

    os.replace(temp_file, filePath)

for path, subdirs, files in os.walk('.'):
    for name in files:
        file_path = os.path.join(path, name)
        if file_path.endswith(".py") and "devops_sdk" in file_path:
            print('removing comments from ' +  file_path)
            remove_comment_from_file(file_path)