Mac OS中SVN工具Versions日期重設指令碼

來源:互聯網
上載者:User

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()

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.