Python style update

This commit is contained in:
Mengjuei 2012-03-21 00:01:17 -07:00
parent b3803637ba
commit 3ed20c1743
1 changed files with 34 additions and 34 deletions

View File

@ -9,42 +9,42 @@ from Foundation import *
from AppKit import * from AppKit import *
def generateRTF(inString="", inFile=""): def generateRTF(inString="", inFile=""):
if len(inString) == 0: return if len(inString) == 0: return
if len(inFile) == 0: return if len(inFile) == 0: return
paragraphStyle = NSMutableParagraphStyle.alloc().init() paragraphStyle = NSMutableParagraphStyle.alloc().init()
paragraphStyle.setAlignment_(NSCenterTextAlignment) paragraphStyle.setAlignment_(NSCenterTextAlignment)
attributedString = NSAttributedString.alloc().initWithString_attributes_(inString, { attributedString = NSAttributedString.alloc().initWithString_attributes_(inString, {
NSParagraphStyleAttributeName: paragraphStyle, NSParagraphStyleAttributeName: paragraphStyle,
NSFontAttributeName: NSFont.systemFontOfSize_(11) NSFontAttributeName: NSFont.systemFontOfSize_(11)
}) })
data = attributedString.RTFFromRange_documentAttributes_(NSMakeRange(0, len(inString)), None) data = attributedString.RTFFromRange_documentAttributes_(NSMakeRange(0, len(inString)), None)
try: os.remove(inFile) try: os.remove(inFile)
except: pass except: pass
data.writeToFile_atomically_(inFile, True) data.writeToFile_atomically_(inFile, True)
os.utime(inFile, None) # Touch the file os.utime(inFile, None) # Touch the file
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv argv = sys.argv
try: try:
path = argv[1] path = argv[1]
except: except:
return return
path = os.path.abspath(path) path = os.path.abspath(path)
cmd = "/usr/bin/git log --format='%h' -1" cmd = "/usr/bin/git log --format='%h' -1"
try: try:
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
lines = "" lines = ""
while True: while True:
line = p.stdout.readline() line = p.stdout.readline()
if not line: break if not line: break
line = line.strip() line = line.strip()
if len(line): lines += line + "\n" if len(line): lines += line + "\n"
lines = lines.strip() lines = lines.strip()
generateRTF("Build: " + lines, os.path.join(path, "Credits.rtf")) generateRTF("Build: " + lines, os.path.join(path, "Credits.rtf"))
except Exception, e: except Exception, e:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())