Edition 1
Abstract
Table of Contents
git clone https://github.com/ClusterLabs/pacemaker.git pacemaker
change-type: affected-code: explanation
where change-type
can be Fix
or Bug
for most bug fixes, Feature
for new features, Log
for changes to log messages or handling, Doc
for changes to documentation or comments, or Test
for changes in CTS and regression tests. You will sometimes see Low
, Med
(or Mid
) and High
used instead for bug fixes, to indicate the severity. The important thing is that only commits with Feature
, Fix
, Bug
, or High
will automatically be included in the change log for the next release. The affected-code
is the name of the component(s) being changed, for example, crmd
or libcrmcommon
(it’s more free-form, so don’t sweat getting it exact). The explanation
briefly describes the change. The git project recommends the entire summary line stay under 50 characters, but more is fine if needed for clarity. Except for the most simple and obvious of changes, the summary should be followed by a blank line and then a longer explanation of why the change was made.
Table of Contents
/* * Copyright (C) <YYYY[-YYYY]> Andrew Beekhof <andrew@beekhof.net> * * This source code is licensed under <LICENSE> WITHOUT ANY WARRANTY. */
<YYYY>
is the year the code was originally created (it is the most important date for copyright purposes, as it establishes priority and the point from which expiration is calculated). If the code is modified in later years, add -YYYY
with the most recent year of modification.
<LICENSE>
should follow the policy set forth in the COPYING
file, generally one of "GNU General Public License version 2 or later (GPLv2+)" or "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)".
*
goes by the variable name, not the type:
char *foo;
*
and after the closing parenthesis in a cast:
char *foo = (char *) bar;
static int foo(void) {
static int function_name(int bar, const char *a, const char *b, const char *c, const char *d) {
static int really_really_long_function_name_this_is_getting_silly_now( int bar, const char *a, const char *b, const char *c, const char *d) {
else
and else if
are on the same line with the ending brace and opening brace, separated by a space:
if (condition1) { statement1; } else if (condition2) { statement2; } else { statement3; }
switch
statement, case
is indented one level, and the body of each case
is indented by another level. The opening brace is on the same line as switch
.
switch (expression) { case 0: command1; break; case 1: command2; break; default: command3; }
static
function names, type names, etc.) must begin with a prefix appropriate to the library, for example, crm_
, pe_
, st_
, lrm_
.
vim
to edit source code can add the following settings to their ~/.vimrc
file to follow Pacemaker C coding guidelines:
" follow Pacemaker coding guidelines when editing C source code files filetype plugin indent on au FileType c setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 autocmd BufNewFile,BufRead *.h set filetype=c let c_space_errors = 1
Table of Contents
[<SHEBANG>] """ <BRIEF-DESCRIPTION> """ # Pacemaker targets compatibility with Python 2.6+ and 3.2+ from __future__ import print_function, unicode_literals, absolute_import, division __copyright__ = "Copyright (C) <YYYY[-YYYY]> Andrew Beekhof <andrew@beekhof.net>" __license__ = "<LICENSE> WITHOUT ANY WARRANTY"
<SHEBANG>
) should be #!/usr/bin/python
. If it is meant to be imported, omit this line.
<BRIEF-DESCRIPTION>
is obviously a brief description of the file’s purpose. The string may contain any other information typically used in a Python file docstring.
import
statement is discussed further in Section 3.2.1, “Python Future Imports”.
<YYYY>
is the year the code was originally created (it is the most important date for copyright purposes, as it establishes priority and the point from which expiration is calculated). If the code is modified in later years, add -YYYY
with the most recent year of modification.
<LICENSE>
should follow the policy set forth in the COPYING
file, generally one of "GNU General Public License version 2 or later (GPLv2+)" or "GNU Lesser General Public License version 2.1 or later (LGPLv2.1+)".
end=' '
parameter rather than a trailing comma.
u
prefix is unnecessary, and must not be used, because it is not available in Python 3.2).
from . import
(rather than just import
). To import one item from a local module, use from .modulename import
(rather than from modulename import
).
/
will always return a floating-point result (use //
if you want the integer floor instead).
as
instead of a comma (e.g. except Exception as e
or except (TypeError, IOError) as e
). Use e.args
to access the error arguments (instead of iterating over or subscripting e
).
in
(not has_key()
) to determine if a dictionary has a particular key.
io
module rather than the native I/O functions (e.g. io.open()
rather than open()
).
t
(text) or b
(binary) mode flag.
class Foo(object):
rather than class Foo:
)
subprocess.Popen()
). Code should handle both possibilities.
items()
, keys()
, and values()
methods of dictionaries return lists in Python 2 and views in Python 3. In many case, no special handling is required, but if the code needs to use list methods on the result, cast the result to list first.
with
or as
.
raise "Bad thing"
).
cmp
parameter of sorting functions (use key
instead, if needed) or the __cmp__()
method of classes (implement rich comparison methods such as __lt__()
instead, if needed).
buffer
type.
argparse
, html
, ipaddress
, sysconfig
, and UserDict
modules
collections.OrderedDict
class
subprocess.run()
function
subprocess.DEVNULL
constant
subprocess
module-specific exceptions
{1, 2, 3}
)
locale.strcoll
and locale.strxfrm
configparser
and ConfigParser
modules
six
(so we don’t have to add them to Pacemaker’s dependencies)
pylint --disable=line-too-long,too-many-lines,too-many-instance-attributes,too-many-arguments,too-many-statements
produces minimal complaints (even better if you don’t need to disable all those checks).
Revision History | |||
---|---|---|---|
Revision 1-0 | Tue Jul 26 2016 | ||
| |||
Revision 1-1 | Mon Aug 29 2016 | ||
|