예제 #1
0
파일: testbasedir.py 프로젝트: boube/minino
    def testJoin(self):
        self.assertEquals("/tmp/config/foo/bar", basedir.save_config_path("foo/bar"))
        self.assertEquals("/tmp/config/foo/bar", basedir.save_config_path("foo", "bar"))

        self.assertEquals("/tmp/share/foo/bar", basedir.save_data_path("foo/bar"))
        self.assertEquals("/tmp/share/foo/bar", basedir.save_data_path("foo", "bar"))

        self.assertEquals(["/tmp/share/foo/bar"], list(basedir.load_data_paths("foo/bar")))
        self.assertEquals(["/tmp/share/foo/bar"], list(basedir.load_data_paths("foo", "bar")))

        self.assertEquals(["/tmp/config/foo/bar"], list(basedir.load_config_paths("foo/bar")))
        self.assertEquals(["/tmp/config/foo/bar"], list(basedir.load_config_paths("foo", "bar")))
예제 #2
0
파일: mime.py 프로젝트: pombredanne/rox-lib
def install_mime_info(application, package_file = None):
	"""Copy 'package_file' as ~/.local/share/mime/packages/<application>.xml.
	If package_file is None, install <app_dir>/<application>.xml.
	If already installed, does nothing. May overwrite an existing
	file with the same name (if the contents are different)"""
	application += '.xml'
	if not package_file:
		package_file = os.path.join(rox.app_dir, application)
	
	new_data = file(package_file).read()

	# See if the file is already installed
		
	package_dir = os.path.join('mime', 'packages')
	resource = os.path.join(package_dir, application)
	for x in basedir.load_data_paths(resource):
		try:
			old_data = file(x).read()
		except:
			continue
		if old_data == new_data:
			return	# Already installed

	global _cache_uptodate
	_cache_uptodate = False
	
	# Not already installed; add a new copy
	try:
		# Create the directory structure...
		new_file = os.path.join(basedir.save_data_path(package_dir), application)

		# Write the file...
		file(new_file, 'w').write(new_data)

		# Update the database...
		if os.path.isdir('/uri/0install/zero-install.sourceforge.net'):
			command = '/uri/0install/zero-install.sourceforge.net/bin/update-mime-database'
		else:
			command = 'update-mime-database'
		if os.spawnlp(os.P_WAIT, command, command, basedir.save_data_path('mime')):
			os.unlink(new_file)
			raise Exception(_("The '%s' command returned an error code!\n" \
					  "Make sure you have the freedesktop.org shared MIME package:\n" \
					  "http://www.freedesktop.org/standards/shared-mime-info.html") % command)
	except:
		rox.report_exception()
예제 #3
0
파일: mime.py 프로젝트: boube/minino
def install_mime_info(application, package_file = None):
	"""Copy 'package_file' as ~/.local/share/mime/packages/<application>.xml.
	If package_file is None, install <app_dir>/<application>.xml.
	If already installed, does nothing. May overwrite an existing
	file with the same name (if the contents are different)"""
	application += '.xml'
	if not package_file:
		package_file = os.path.join(rox.app_dir, application)
	
	new_data = file(package_file).read()

	# See if the file is already installed
		
	package_dir = os.path.join('mime', 'packages')
	resource = os.path.join(package_dir, application)
	for x in basedir.load_data_paths(resource):
		try:
			old_data = file(x).read()
		except:
			continue
		if old_data == new_data:
			return	# Already installed

	global _cache_uptodate
	_cache_uptodate = False
	
	# Not already installed; add a new copy
	try:
		# Create the directory structure...
		new_file = os.path.join(basedir.save_data_path(package_dir), application)

		# Write the file...
		file(new_file, 'w').write(new_data)

		# Update the database...
		if os.path.isdir('/uri/0install/zero-install.sourceforge.net'):
			command = '/uri/0install/zero-install.sourceforge.net/bin/update-mime-database'
		else:
			command = 'update-mime-database'
		if os.spawnlp(os.P_WAIT, command, command, basedir.save_data_path('mime')):
			os.unlink(new_file)
			raise Exception(_("The '%s' command returned an error code!\n" \
					  "Make sure you have the freedesktop.org shared MIME package:\n" \
					  "http://www.freedesktop.org/standards/shared-mime-info.html") % command)
	except:
		rox.report_exception()
예제 #4
0
    def testJoin(self):
        self.assertEquals('/tmp/config/foo/bar',
                          basedir.save_config_path('foo/bar'))
        self.assertEquals('/tmp/config/foo/bar',
                          basedir.save_config_path('foo', 'bar'))

        self.assertEquals('/tmp/share/foo/bar',
                          basedir.save_data_path('foo/bar'))
        self.assertEquals('/tmp/share/foo/bar',
                          basedir.save_data_path('foo', 'bar'))

        self.assertEquals(['/tmp/share/foo/bar'],
                          list(basedir.load_data_paths('foo/bar')))
        self.assertEquals(['/tmp/share/foo/bar'],
                          list(basedir.load_data_paths('foo', 'bar')))

        self.assertEquals(['/tmp/config/foo/bar'],
                          list(basedir.load_config_paths('foo/bar')))
        self.assertEquals(['/tmp/config/foo/bar'],
                          list(basedir.load_config_paths('foo', 'bar')))
예제 #5
0
	def testJoin(self):
		self.assertEquals('/tmp/config/foo/bar',
				  basedir.save_config_path('foo/bar'))
		self.assertEquals('/tmp/config/foo/bar',
				  basedir.save_config_path('foo', 'bar'))

		self.assertEquals('/tmp/share/foo/bar',
				  basedir.save_data_path('foo/bar'))
		self.assertEquals('/tmp/share/foo/bar',
				  basedir.save_data_path('foo', 'bar'))

		self.assertEquals(['/tmp/share/foo/bar'],
				  list(basedir.load_data_paths('foo/bar')))
		self.assertEquals(['/tmp/share/foo/bar'],
				  list(basedir.load_data_paths('foo', 'bar')))

		self.assertEquals(['/tmp/config/foo/bar'],
				  list(basedir.load_config_paths('foo/bar')))
		self.assertEquals(['/tmp/config/foo/bar'],
				  list(basedir.load_config_paths('foo', 'bar')))