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

简介: Versions是一个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()
	
	



 

目录
相关文章
|
4月前
|
开发工具 git iOS开发
Mac 安装软件包管理工具Homebrew
Mac 安装软件包管理工具Homebrew
|
4月前
|
存储 Shell
Mac终端工具Terminal (3):在Mac上的终端中执行命令和运行工具
Mac终端工具Terminal (3):在Mac上的终端中执行命令和运行工具
289 0
|
4月前
|
Shell
Mac终端工具Terminal (2):打开新终端窗口或者页签
Mac终端工具Terminal (2):打开新终端窗口或者页签
344 0
|
4月前
|
Shell 网络安全 iOS开发
最好用的SSH工具Royal TSX for mac使用教程
众所周知,在 Windows上我们经常用到的shell工具可能非 xshell莫属了。但是xshell却并没有开发mac 版本,我们只能用其他的工具替代了。 在我用过几个ssh工具之后,我觉得在macOS上最好用的ssh工具客户端必须是 Royal TSX,它和使用xhell的感觉简直一模一样。 Royal TSX是一款功能非常强大适用于 Mac 的远程连接管理工具。兼容多种连接类型,比如:RDP、VNC、基于SSH连接的终端,SFTP/FTP/SCP或基于Web的连接管理,Royal TSX 都可以满足您的要求!
641 0
最好用的SSH工具Royal TSX for mac使用教程
|
18天前
|
iOS开发 MacOS
macOS开机自启动执行脚本
【8月更文挑战第23天】在macOS上设置开机自动执行脚本可通过三种方式:一是利用“系统偏好设置”中的“用户与群组”功能直接添加脚本或应用;二是通过创建`.plist`文件并放置于`LaunchAgents`目录,这种方式能更精细地控制脚本运行;三是使用cron任务,在系统启动时执行脚本,但该方法不太适用于图形界面程序且可能受限于启动顺序。每种方法各有优缺点,需根据实际情况选择。
|
27天前
|
监控 网络安全 数据安全/隐私保护
Mac服务器ssh连接工具
Mac服务器ssh连接工具
43 2
|
4月前
|
安全 Java iOS开发
MAC OS X 硬盘安装详细分解教程
MAC OS X 硬盘安装详细分解教程
180 1
|
4月前
|
编解码 Oracle iOS开发
VirtualBox虚拟机安装Mac OS X Lion系统详解
VirtualBox虚拟机安装Mac OS X Lion系统详解
255 1
|
4月前
|
安全 iOS开发 MacOS
Mac pro升级 MacOS 10.15 Catalina 后根目录是只读的, Recovery OS不能访问
Mac pro升级 MacOS 10.15 Catalina 后根目录是只读的, Recovery OS不能访问
61 0
|
4月前
|
数据库管理
Mac检出svn checkout报错 svn: E200030: SQLite 编译为 3.39.5,但是运行于 3.39.4
Mac检出svn checkout报错 svn: E200030: SQLite 编译为 3.39.5,但是运行于 3.39.4
175 0