comparison mercurial/util.py @ 14262:23cd7eeff678

util: rename _windows_reserved_filenames and _windows_reserved_chars
author Adrian Buehlmann <adrian@cadifra.com>
date Sat, 07 May 2011 22:25:20 +0200
parents 34ec9b313638
children 4030630fb59c
comparison
equal deleted inserted replaced
14261:e3649bcca3f6 14262:23cd7eeff678
443 shutil.copy(src, dst) 443 shutil.copy(src, dst)
444 num += 1 444 num += 1
445 445
446 return hardlink, num 446 return hardlink, num
447 447
448 _windows_reserved_filenames = '''con prn aux nul 448 _winreservednames = '''con prn aux nul
449 com1 com2 com3 com4 com5 com6 com7 com8 com9 449 com1 com2 com3 com4 com5 com6 com7 com8 com9
450 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split() 450 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
451 _windows_reserved_chars = ':*?"<>|' 451 _winreservedchars = ':*?"<>|'
452 def checkwinfilename(path): 452 def checkwinfilename(path):
453 '''Check that the base-relative path is a valid filename on Windows. 453 '''Check that the base-relative path is a valid filename on Windows.
454 Returns None if the path is ok, or a UI string describing the problem. 454 Returns None if the path is ok, or a UI string describing the problem.
455 455
456 >>> checkwinfilename("just/a/normal/path") 456 >>> checkwinfilename("just/a/normal/path")
470 ''' 470 '''
471 for n in path.replace('\\', '/').split('/'): 471 for n in path.replace('\\', '/').split('/'):
472 if not n: 472 if not n:
473 continue 473 continue
474 for c in n: 474 for c in n:
475 if c in _windows_reserved_chars: 475 if c in _winreservedchars:
476 return _("filename contains '%s', which is reserved " 476 return _("filename contains '%s', which is reserved "
477 "on Windows") % c 477 "on Windows") % c
478 if ord(c) <= 31: 478 if ord(c) <= 31:
479 return _("filename contains %r, which is invalid " 479 return _("filename contains %r, which is invalid "
480 "on Windows") % c 480 "on Windows") % c
481 base = n.split('.')[0] 481 base = n.split('.')[0]
482 if base and base.lower() in _windows_reserved_filenames: 482 if base and base.lower() in _winreservednames:
483 return _("filename contains '%s', which is reserved " 483 return _("filename contains '%s', which is reserved "
484 "on Windows") % base 484 "on Windows") % base
485 t = n[-1] 485 t = n[-1]
486 if t in '. ': 486 if t in '. ':
487 return _("filename ends with '%s', which is not allowed " 487 return _("filename ends with '%s', which is not allowed "