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

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

 

#!/usr/bin/env python

import os, sys, re, plistlib, subprocess, re, time



userdir = 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_path
	os.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 False

def 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_a1
		os.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_b1
		os.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()
	
	


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值