SVN tool versions date reset script in Mac OS

Source: Internet
Author: User

Versions is a great SVN tool in Mac OS, but it has a date limit. Someone on the Internet provides a script to reset versions's use date, which is worth learning. Paste it to make a record.

 

#!/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()
	
	

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.