public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Liming" <liming.gao@intel.com>
To: "Guo, Dongao" <dongao.guo@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH v2] Formalize source files to follow DOS format
Date: Mon, 4 Jun 2018 07:04:22 +0000	[thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E292400@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <1527580881-18168-1-git-send-email-dongao.guo@intel.com>

Dongao:
  I just meet with the case that is not expected to be modified, such as the third party openssl code in CryptoPkg. So, I suggest to add one option to describe the exception direction name or file name. 

Thanks
Liming
>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Dongao Guo
>Sent: Tuesday, May 29, 2018 4:01 PM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming <liming.gao@intel.com>
>Subject: [edk2] [PATCH v2] Formalize source files to follow DOS format
>
>From: Liming Gao <liming.gao@intel.com>
>
>V2:
>add version,description,copyright.
>add flag -v,-q,--append-extensions,--override-extensions,--debug.
>-q will omit default output,-v and --debug are not implemented.
>add default file extensions.
>support input of file path.
>support muliple input path.
>simplify comment.
>change 'pattern'.encode() to b'pattern',I think this will be better.
>change naming of variable and function to keep the same with BinToPcd.py
>
>V1:
>FormatDosFiles.py is added to clean up dos source files. It bases on
>the rules defined in EDKII C Coding Standards Specification.
>5.1.2 Do not use tab characters
>5.1.6 Only use CRLF (Carriage Return Line Feed) line endings.
>5.1.7 All files must end with CRLF
>No trailing white space in one line. (To be added in spec)
>
>The source files in edk2 project with the below postfix are dos format.
>.h .c .nasm .nasmb .asm .S .inf .dec .dsc .fdf .uni .asl .aslc .vfr .idf
>.txt .bat .py
>
>The package maintainer can use this script to clean up all files in his
>package. The prefer way is to create one patch per one package.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Liming Gao <liming.gao@intel.com>
>Signed-off-by: Dongao Guo <dongao.guo@intel.com>
>
>---
> BaseTools/Scripts/FormatDosFiles.py | 94
>+++++++++++++++++++++++++++++++++++++
> 1 file changed, 94 insertions(+)
> create mode 100644 BaseTools/Scripts/FormatDosFiles.py
>
>diff --git a/BaseTools/Scripts/FormatDosFiles.py
>b/BaseTools/Scripts/FormatDosFiles.py
>new file mode 100644
>index 0000000..fa969ed
>--- /dev/null
>+++ b/BaseTools/Scripts/FormatDosFiles.py
>@@ -0,0 +1,94 @@
>+# @file FormatDosFiles.py
>+# This script format the source files to follow dos style.
>+# It supports Python2.x and Python3.x both.
>+#
>+#  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
>+#
>+#  This program and the accompanying materials
>+#  are licensed and made available under the terms and conditions of the
>BSD License
>+#  which accompanies this distribution.  The full text of the license may be
>found at
>+#  http://opensource.org/licenses/bsd-license.php
>+#
>+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
>BASIS,
>+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
>EXPRESS OR IMPLIED.
>+#
>+
>+#
>+# Import Modules
>+#
>+import argparse
>+import os
>+import os.path
>+import re
>+import sys
>+import copy
>+
>+__prog__        = 'FormatDosFiles'
>+__version__     = '%s Version %s' % (__prog__, '0.12 ')
>+__copyright__   = 'Copyright (c) 2018 3, Intel Corporation. All rights reserved.'
>+__description__ = 'Convert source files to meet the EDKII C Coding
>Standards Specification.\n'
>+DEFAULT_EXT_LIST = ['.h', '.c', '.nasm', '.nasmb', '.asm', '.S', '.inf', '.dec', '.dsc',
>'.fdf', '.uni', '.asl', '.aslc', '.vfr', '.idf', '.txt', '.bat', '.py']
>+
>+#For working in python2 and python3 environment, re pattern should use
>binary string, which is bytes type in python3.
>+#Because in python3,read from file in binary mode will return bytes type,and
>in python3 bytes type can not be mixed with str type.
>+def FormatFile(FilePath, Args):
>+    with open(FilePath, 'rb') as Fd:
>+        Content = Fd.read()
>+        Fd.close()
>+        # Convert the line endings to CRLF
>+        Content = re.sub(br'([^\r])\n', br'\1\r\n', Content)
>+        Content = re.sub(br'^\n', br'\r\n', Content, flags=re.MULTILINE)
>+        # Add a new empty line if the file is not end with one
>+        Content = re.sub(br'([^\r\n])$', br'\1\r\n', Content)
>+        # Remove trailing white spaces
>+        Content = re.sub(br'[ \t]+(\r\n)', br'\1', Content, flags=re.MULTILINE)
>+        # Replace '\t' with two spaces
>+        Content = re.sub(b'\t', b'  ', Content)
>+        with open(FilePath, 'wb') as Fd:
>+            Fd.write(Content)
>+            Fd.close()
>+            if not Args.Quiet:
>+                print(FilePath)
>+
>+def FormatFilesInDir(DirPath, ExtList, Args):
>+
>+    FileList = []
>+    for DirPath, DirNames, FileNames in os.walk(DirPath):
>+        for FileName in [f for f in FileNames if any(f.endswith(ext) for ext in
>ExtList)]:
>+            FileList.append(os.path.join(DirPath, FileName))
>+    for File in FileList:
>+        FormatFile(File, Args)
>+
>+if __name__ == "__main__":
>+    parser =
>argparse.ArgumentParser(prog=__prog__,description=__description__ +
>__copyright__, conflict_handler = 'resolve')
>+
>+    parser.add_argument('Path', nargs='+',
>+                        help='the path for files to be converted.It could be directory or
>file path.')
>+    parser.add_argument('--version', action='version', version=__version__)
>+    parser.add_argument('--append-extensions', dest='AppendExt', nargs='+',
>+                        help='append file extensions filter to default extensions.
>(Example: .txt .c .h)')
>+    parser.add_argument('--override-extensions', dest='OverrideExt',
>nargs='+',
>+                        help='override file extensions filter on default extensions.
>(Example: .txt .c .h)')
>+    parser.add_argument('-v', '--verbose', dest='Verbose', action='store_true',
>+                        help='increase output messages')
>+    parser.add_argument('-q', '--quiet', dest='Quiet', action='store_true',
>+                        help='reduce output messages')
>+    parser.add_argument('--debug', dest='Debug', type=int, metavar='[0-9]',
>choices=range(0, 10), default=0,
>+                        help='set debug level')
>+
>+    args = parser.parse_args()
>+    DefaultExt = copy.copy(DEFAULT_EXT_LIST)
>+
>+    if args.OverrideExt is not None:
>+        DefaultExt = args.OverrideExt
>+    if args.AppendExt is not None:
>+        DefaultExt = list(set(DefaultExt + args.AppendExt))
>+
>+    for Path in args.Path:
>+        if not os.path.exists(Path):
>+            print("not exists path: {0}".format(Path))
>+            sys.exit(1)
>+        if os.path.isdir(Path):
>+            FormatFilesInDir(Path, DefaultExt, args)
>+        elif os.path.isfile(Path):
>+            FormatFile(Path, args)
>--
>2.6.1.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


      reply	other threads:[~2018-06-04  7:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29  8:01 [PATCH v2] Formalize source files to follow DOS format Dongao Guo
2018-06-04  7:04 ` Gao, Liming [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A89E2EF3DFEDB4C8BFDE51014F606A14E292400@SHSMSX104.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox