Mac OS中SVN工具Versions日期重置脚本

来源:互联网 发布:淘宝刷钻价格表 编辑:程序博客网 时间:2024/06/15 20:46

Versions是一个Mac OS下挺棒的SVN工具,不过有日期限制。网上有人提供了将Versions的使用日期重置的脚本,这个脚本有些值得学习的地方。贴出来做个记录。

 

#!/usr/bin/env pythonimport os, sys, re, plistlib, subprocess, re, timeuserdir = os.path.expanduser('~')prefdir = os.path.join(userdir, 'Library/Preferences')pfile_a = os.path.join(prefdir,'com.madebysofa.Versions.plist')pfile_b = 'com.picodev.Versions.plist'hfile_a = '.CF89AA64'hfile_b = '.FB64CF89'globalprefs = os.path.join(prefdir, '.GlobalPreferences.plist')def convert_plist_to_xml(plist_path):cmdline = '/usr/bin/plutil -convert xml1 "%s"' % plist_pathos.system(cmdline)def isVersionsRunning():p = subprocess.Popen(['ps','-Ac'],stdout=subprocess.PIPE)output = p.stdout.read()apps_re = re.search('^([0-9]+).*Versions$', output, re.M)if apps_re:return int(apps_re.group(1))else:return Falsedef killRunningVersions():pid = isVersionsRunning()if pid:sys.stdout.write('Stopping currently running Versions...\n')os.system('kill %d' % pid)while isVersionsRunning():time.sleep(0.1)def relaunchVersions():os.system('open -a /Applications/Versions.app')if __name__ == '__main__':killRunningVersions()pfile_a_path = os.path.join(prefdir, pfile_a)pfile_b_path = os.path.join(prefdir, pfile_b)# --1) Start by deleting the hidden files.hfile_a1 = os.path.join(userdir, hfile_a)if os.path.exists(hfile_a1):print 'Removing "%s"'%hfile_a1os.remove(hfile_a1)hfile_b1 = os.path.join(os.path.join(userdir, 'Library/'), hfile_b)if os.path.exists(hfile_b1):print 'Removing "%s"'%hfile_b1os.remove(hfile_b1)# -- 2) Now, delete the expiry token from the globalprefs file...if os.path.exists(globalprefs):convert_plist_to_xml(globalprefs)pl = plistlib.readPlist(globalprefs)if 'com.madebysofa.Versions.ezsRequiredToken' in pl.keys():sys.stdout.write('Removing expiry token from .Globalprefs...\n')del pl['com.madebysofa.Versions.ezsRequiredToken']plistlib.writePlist(pl, globalprefs)# -- 2) Make sure that the "FirstRunDate" is also removed...if os.path.exists(pfile_a):convert_plist_to_xml(pfile_a)pl = plistlib.readPlist(pfile_a)if 'FirstRunDate' in pl.keys():sys.stdout.write('Removing FirstRunDate from "%s"\n' % pfile_a)del pl['FirstRunDate']if 'EZSBookmarksSelectionMask' in pl.keys():sys.stdout.write('Removing EZSBookmarksSelectionMask from "%s"' % pfile_a)del pl['EZSBookmarksSelectionMask']plistlib.writePlist(pl, pfile_a)sys.stdout.write('Launching Versions....')relaunchVersions()


 

原创粉丝点击