File: pathcontrol.py

package info (click to toggle)
fontypython 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,152 kB
  • ctags: 559
  • sloc: python: 3,619; makefile: 10
file content (108 lines) | stat: -rw-r--r-- 3,614 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
##	Fonty Python Copyright (C) 2006, 2007, 2008, 2009 Donn.C.Ingle
##	Contact: donn.ingle@gmail.com - I hope this email lasts.
##
##	This file is part of Fonty Python.
##	Fonty Python is free software: you can redistribute it and/or modify
##	it under the terms of the GNU General Public License as published by
##	the Free Software Foundation, either version 3 of the License, or
##	(at your option) any later version.
##
##	Fonty Python is distributed in the hope that it will be useful,
##	but WITHOUT ANY WARRANTY; without even the implied warranty of
##	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##	GNU General Public License for more details.
##
##	You should have received a copy of the GNU General Public License
##	along with Fonty Python.  If not, see <http://www.gnu.org/licenses/>.

import os

class PathControl:
	"""
	1. Makes the .fontypython path
	2. Provide paths for fontypython on Linux
	3. Provide list of pog names (without the .pog extension)
	4. Provide a list of pog FILE names (with .pog extension)
	
	* All these vars contain/return BYTE STRING paths and files.
	"""
	
	def __init__(self, makeFolder=True ):
		## __HOME will be a BYTE STRING (Under Linux)
		self.__HOME = os.environ['HOME']
		
		self.__fphomepath = self.__HOME + "/.fontypython/" # byte string
		self.__fpconffile = self.__HOME + "/.fontypython/fp.conf" # byte string
		
		
		## Is there a .fonts folder ?
		##
		## EDIT
		##
		## April 2012 - Kartik Mistry (kartik@debian.org)
		## informed me there was a bug in some esoteric build
		## of some voodoo Debian process and that I should
		## simply skip the check and creation of .fonts directory.

		#if not os.path.exists(self.__HOME + "/.fonts"):
			## We gotta make it.
		#	try:
		#		os.mkdir(self.__HOME + "/.fonts")
		#	except:
		#		print _("""
		# Couldn't make the .fonts folder in %s
		# Please check your write permissions and try again.""") % self.__HOME
		#	raise SystemExit
		
		## EDIT
		## August 2012
		## If there is no .fonts dir, install pog fails. The cursor keeps busy and nothing
		## further happens. Here my suggestion: only perform a test, without creating the dir.
		
		#if not os.path.exists(self.__HOME + "/.fonts"):
		#	print _("""
		#It seems there is no %s/.fonts folder or there are wrong permissions.
		#Please create it manually to be able to install your fonts with FontyPython.""") % self.__HOME
			#raise SystemExit
		
		## end of michael edit.

		##Edit Donn June 25, 2016
		## Remarked Michael's edit. Moved the test for missing .fonts dir to
		## fontcontrol.py in the install() function
		
		self.__userfontpath = self.__HOME + "/.fonts"

		## June 25, 2016
		## Some distros do not have the .fonts directory by default. :( :O
		## This is a disaster. 
		## I have shifted the test for this into fontcontrol install()

		## Make ~/.fontypython
		if makeFolder:
			if not os.path.exists(self.__fphomepath):
				try:
					os.makedirs(self.__fphomepath) #using makedirs - just in case.
				except:
					print _("""
Couldn't make the folder in %s
Please check your write permissions and try again.""") % self.__fphomepath
					raise SystemExit
			
	def appPath(self): 
		""" Kind of spastic, but I was in a get/set mode"""
		return self.__fphomepath
		
	def appConf(self): 
		return self.__fpconffile
		
	def getPogNames(self): 
		## We pass a byte string path to os.listdir therefore this function
		## return a LIST OF BYTE STRINGS.
		return [ f[0:-4] for f in os.listdir(self.__fphomepath) if f.endswith(".pog") ]

	def userFontPath(self): 
		return self.__userfontpath
		
	def home(self) : 
		return self.__HOME