Fix style in a number of places

- Fixes lines where line with N tab indent is followed by a line with N+2 tab 
  indent or greater (most of such lines were already fixed in 
  ae92d83eae5142322ff20b9aa81eb53b0b363575, but regex used there has one flow: 
  it does not catches lines where N=0 for which case first `\+` needs to be 
  replaced with `*`).
- Replace print(…, file=sys.stderr) with sys.stderr.write in powerline-daemon.
This commit is contained in:
ZyX 2014-08-31 21:29:03 +04:00
parent a2b58370c4
commit 0e98bc2d4f
5 changed files with 41 additions and 42 deletions

View File

@ -213,13 +213,17 @@ class INotifyTreeWatcher(INotify):
def add_watch(self, path): def add_watch(self, path):
bpath = path if isinstance(path, bytes) else path.encode(self.fenc) bpath = path if isinstance(path, bytes) else path.encode(self.fenc)
wd = self._add_watch(self._inotify_fd, ctypes.c_char_p(bpath), wd = self._add_watch(
# Ignore symlinks and watch only directories self._inotify_fd,
self.DONT_FOLLOW | self.ONLYDIR | ctypes.c_char_p(bpath),
self.MODIFY | self.CREATE | self.DELETE | # Ignore symlinks and watch only directories
self.MOVE_SELF | self.MOVED_FROM | self.MOVED_TO | self.DONT_FOLLOW | self.ONLYDIR |
self.ATTRIB | self.DELETE_SELF)
self.MODIFY | self.CREATE | self.DELETE |
self.MOVE_SELF | self.MOVED_FROM | self.MOVED_TO |
self.ATTRIB | self.DELETE_SELF
)
if wd == -1: if wd == -1:
eno = ctypes.get_errno() eno = ctypes.get_errno()
if eno == errno.ENOTDIR: if eno == errno.ENOTDIR:

View File

@ -560,8 +560,8 @@ def check_top_theme(theme, data, context, echoerr):
return True, False, False return True, False, False
divider_spec = Spec().type(unicode).len('le', 3, divider_spec = Spec().type(unicode).len(
lambda value: 'Divider {0!r} is too large!'.format(value)).copy 'le', 3, (lambda value: 'Divider {0!r} is too large!'.format(value))).copy
ext_theme_spec = Spec().type(unicode).func(lambda *args: check_config('themes', *args)).copy ext_theme_spec = Spec().type(unicode).func(lambda *args: check_config('themes', *args)).copy
top_theme_spec = Spec().type(unicode).func(check_top_theme).copy top_theme_spec = Spec().type(unicode).func(check_top_theme).copy
ext_spec = Spec( ext_spec = Spec(

View File

@ -264,32 +264,25 @@ class Constructor(BaseConstructor):
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:null', 'tag:yaml.org,2002:null', Constructor.construct_yaml_null)
Constructor.construct_yaml_null)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:bool', 'tag:yaml.org,2002:bool', Constructor.construct_yaml_bool)
Constructor.construct_yaml_bool)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:int', 'tag:yaml.org,2002:int', Constructor.construct_yaml_int)
Constructor.construct_yaml_int)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:float', 'tag:yaml.org,2002:float', Constructor.construct_yaml_float)
Constructor.construct_yaml_float)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:str', 'tag:yaml.org,2002:str', Constructor.construct_yaml_str)
Constructor.construct_yaml_str)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:seq', 'tag:yaml.org,2002:seq', Constructor.construct_yaml_seq)
Constructor.construct_yaml_seq)
Constructor.add_constructor( Constructor.add_constructor(
'tag:yaml.org,2002:map', 'tag:yaml.org,2002:map', Constructor.construct_yaml_map)
Constructor.construct_yaml_map)
Constructor.add_constructor(None, Constructor.add_constructor(
Constructor.construct_undefined) None, Constructor.construct_undefined)

View File

@ -110,21 +110,21 @@ class Resolver(BaseResolver):
Resolver.add_implicit_resolver( Resolver.add_implicit_resolver(
'tag:yaml.org,2002:bool', 'tag:yaml.org,2002:bool',
re.compile(r'''^(?:true|false)$''', re.X), re.compile(r'''^(?:true|false)$''', re.X),
list('yYnNtTfFoO')) list('yYnNtTfFoO'))
Resolver.add_implicit_resolver( Resolver.add_implicit_resolver(
'tag:yaml.org,2002:float', 'tag:yaml.org,2002:float',
re.compile(r'^-?(?:0|[1-9]\d*)(?=[.eE])(?:\.\d+)?(?:[eE][-+]?\d+)?$', re.X), re.compile(r'^-?(?:0|[1-9]\d*)(?=[.eE])(?:\.\d+)?(?:[eE][-+]?\d+)?$', re.X),
list('-0123456789')) list('-0123456789'))
Resolver.add_implicit_resolver( Resolver.add_implicit_resolver(
'tag:yaml.org,2002:int', 'tag:yaml.org,2002:int',
re.compile(r'^(?:0|-?[1-9]\d*)$', re.X), re.compile(r'^(?:0|-?[1-9]\d*)$', re.X),
list('-0123456789')) list('-0123456789'))
Resolver.add_implicit_resolver( Resolver.add_implicit_resolver(
'tag:yaml.org,2002:null', 'tag:yaml.org,2002:null',
re.compile(r'^null$', re.X), re.compile(r'^null$', re.X),
['n']) ['n'])

View File

@ -246,7 +246,7 @@ def daemonize(stdin=os.devnull, stdout=os.devnull, stderr=os.devnull):
# exit first parent # exit first parent
sys.exit(0) sys.exit(0)
except OSError as e: except OSError as e:
print ("fork #1 failed: %d (%s)" % (e.errno, e.strerror), file=sys.stderr) sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1) sys.exit(1)
# decouple from parent environment # decouple from parent environment
@ -261,7 +261,7 @@ def daemonize(stdin=os.devnull, stdout=os.devnull, stderr=os.devnull):
# exit from second parent # exit from second parent
sys.exit(0) sys.exit(0)
except OSError as e: except OSError as e:
print ("fork #2 failed: %d (%s)" % (e.errno, e.strerror), file=sys.stderr) sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1) sys.exit(1)
# Redirect standard file descriptors. # Redirect standard file descriptors.
@ -399,16 +399,18 @@ def main():
# Create a locked pid file containing the daemon's PID # Create a locked pid file containing the daemon's PID
if lockpidfile() is None: if lockpidfile() is None:
if not args.quiet: if not args.quiet:
print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]), sys.stderr.write(
file=sys.stderr) 'The daemon is already running. Use %s -k to kill it.\n' % (
os.path.basename(sys.argv[0])))
raise SystemExit(1) raise SystemExit(1)
# Bind to address or bail if we cannot bind # Bind to address or bail if we cannot bind
sock = check_existing() sock = check_existing()
if sock is None: if sock is None:
if not args.quiet: if not args.quiet:
print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]), sys.stderr.write(
file=sys.stderr) 'The daemon is already running. Use %s -k to kill it.\n' % (
os.path.basename(sys.argv[0])))
raise SystemExit(1) raise SystemExit(1)
if args.foreground: if args.foreground: