about summary refs log tree commit diff stats
path: root/shell/README.md
Commit message (Collapse)AuthorAgeFilesLines
* .Kartik Agaram2021-04-261-5/+5
|
* .Kartik K. Agaram2021-04-251-1/+1
|
* a troubleshooting noteKartik K. Agaram2021-04-251-0/+11
|
* .Kartik K. Agaram2021-04-251-2/+0
|
* expand memory to 2GBKartik K. Agaram2021-04-251-4/+4
| | | | | | | | It requires more than 1GB to fill the screen with a chessboard pattern using the definition in shell/iterative-definitions.limg. I also speed up the chessboard program by clearing the screen up front and then only rendering the white pixels.
* bugfix; thanks Max BernsteinKartik Agaram2021-04-241-1/+1
|
* .Kartik Agaram2021-04-231-2/+16
|
* shell: some example definitionsKartik Agaram2021-04-231-0/+6
|
* faster emulationKartik K. Agaram2021-04-221-2/+2
| | | | Thanks Maxwell Bernstein for pointing this out 🤦‍♂️
* .Kartik K. Agaram2021-04-161-3/+3
|
* bochs support for disk drivesKartik K. Agaram2021-03-231-0/+8
|
* .Kartik K. Agaram2021-03-221-1/+1
|
* shell: gracefully handle missing data diskKartik K. Agaram2021-03-221-4/+9
|
* shell: read initial expression from secondary diskKartik K. Agaram2021-03-211-1/+16
| | | | See shell/README.md for (extremely klunky) instructions.
* .Kartik K. Agaram2021-03-081-1/+1
|
* .Kartik K. Agaram2021-03-081-3/+3
|
* .Kartik K. Agaram2021-03-081-1/+1
|
* .Kartik K. Agaram2021-03-081-0/+13
|
* readme for the Mu shellKartik K. Agaram2021-03-081-0/+8
t;numerical" sort to "natural" sort' href='/akspecs/ranger/commit/ranger/fsobject/fsobject.py?h=v1.9.3&id=9b3d4455ad389138c9b63d5153d03c4cfbee0672'>9b3d4455 ^
a4570538 ^
46693c4b ^
863f85ce ^



863f85ce ^

46693c4b ^
863f85ce ^











ca44b076 ^
863f85ce ^











3de15ddd ^
3de15ddd ^
863f85ce ^

fae694a0 ^
83f08a2c ^
83f08a2c ^

fae694a0 ^
9506fb8e ^
16246965 ^
437c12d9 ^
ae943ecb ^
2bd40e06 ^
3de15ddd ^
b810fe28 ^
50d31c9d ^

b810fe28 ^

b810fe28 ^
9b83f114 ^


46693c4b ^
8f2f1767 ^
46693c4b ^
8f2f1767 ^
46693c4b ^
a44749f6 ^
46693c4b ^



a44749f6 ^
9b3d4455 ^

ba16a2e4 ^
9b3d4455 ^



ba16a2e4 ^
9b3d4455 ^

9506fb8e ^
3de15ddd ^
9506fb8e ^
fae694a0 ^
871c502d ^
4fc56903 ^
ea87d005 ^
b810fe28 ^
3de15ddd ^
6bd1c592 ^


a4570538 ^
4ffef98c ^

b810fe28 ^
4ffef98c ^


b810fe28 ^
90f204e3 ^
b810fe28 ^


4ffef98c ^
b810fe28 ^
4ffef98c ^

















ea87d005 ^
3201b163 ^


ea87d005 ^
3201b163 ^

99e6cf47 ^
b810fe28 ^
46693c4b ^








fae694a0 ^
ec5dfcb1 ^

b4b0eb24 ^

b810fe28 ^

3566114b ^
863f85ce ^


92b730a0 ^
3566114b ^
863f85ce ^
92b730a0 ^
863f85ce ^

3566114b ^
92b730a0 ^
30b25795 ^
3566114b ^
863f85ce ^
92b730a0 ^
863f85ce ^

ca44b076 ^
3566114b ^
ca44b076 ^
3566114b ^

3566114b ^
92b730a0 ^
















863f85ce ^
















92b730a0 ^
863f85ce ^
92b730a0 ^
863f85ce ^

30b25795 ^
cfdbb9d6 ^



863f85ce ^
4fb1670e ^
863f85ce ^
4fb1670e ^


cfdbb9d6 ^
863f85ce ^

6c34428d ^
863f85ce ^


cfdbb9d6 ^
e74ac575 ^
298c72a2 ^
cfdbb9d6 ^
4fb1670e ^

fae694a0 ^
fae694a0 ^
ec5dfcb1 ^

b4b0eb24 ^

863f85ce ^

50d31c9d ^
c2a89082 ^
863f85ce ^
c2a89082 ^
ec5dfcb1 ^
c1a50251 ^
fae694a0 ^

fae694a0 ^
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
                                                                 
 



                                                                      
 






                                                                       
 


                                                                             
 
         
                                                     
                     
                                                                          
                      
                                               
                                                
                                  
                                                  
                                                    
 
                                                  
 
                                         
                  



                       

                    
                           











                        
                                                                     











                              
 
                           

                
 
                                                                  

                                            
                                
                                              
                                                           
                                                                                  
                                            
                                      
 
                    

                                                                        

                                             
 


                                                                             
                      
                                         
                                                  
 
                      
                           



                                                                               
 

                                   
                                                           



                                                                         
                                                           

                                                                               
                          
                                                                   
                                     
 
                      
                                                                        
 
                               
                                                                                    


                                                 
                                                                                 

                                           
 


                                                               
                                                                   
                                                                 


                                                                                    
                                                                                       
 

















                                                   
 


                                                                
 

                                                                           
                                           
 








                                                                                           
                       

                                                                             

                                                      

                                  
 


                                                                          
                               
                                
                                                  
                                                                         

                                                          
                                           
                                                                 
                     
                            
                                                      
                                                                                 

                                                             
                                                  
                               
                                                   

                                     
 
















                                                                                
















                                                                                 
                           
                                                                
                                           

                                    
 



                                                
                                     
                                     
                                  


                                     
 

                                        
                                                                      


                                                          
                                     
                                                         
                                          
 

                                                 
 
                                   

                                                                            

                               

                                   
                                   
                    
                                                              
                               
                                         
                                                                     

                                   
                            
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

CONTAINER_EXTENSIONS = ('7z', 'ace', 'ar', 'arc', 'bz', 'bz2', 'cab', 'cpio',
	'cpt', 'dgc', 'dmg', 'gz', 'iso', 'jar', 'msi', 'pkg', 'rar', 'shar',
	'tar', 'tbz', 'tgz', 'xar', 'xz', 'zip')

import re
from os import access, listdir, lstat, readlink, stat
from time import time
from os.path import abspath, basename, dirname, realpath, splitext, extsep
from . import BAD_INFO
from ranger.core.shared import FileManagerAware
from ranger.ext.shell_escape import shell_escape
from ranger.ext.spawn import spawn
from ranger.ext.lazy_property import lazy_property
from ranger.ext.human_readable import human_readable

_extract_number_re = re.compile(r'([^0-9]?)(\d*)')

class FileSystemObject(FileManagerAware):
	(basename,
	basename_lower,
	dirname,
	extension,
	infostring,
	path,
	permissions,
	stat) = (None,) * 8

	(content_loaded,
	force_load,

	is_device,
	is_directory,
	is_file,
	is_fifo,
	is_link,
	is_socket,

	accessible,
	exists,       # "exists" currently means "link_target_exists"
	loaded,
	marked,
	runnable,
	stopped,
	tagged,

	audio,
	container,
	document,
	image,
	media,
	video) = (False,) * 21

	mimetype_tuple = ()
	size = 0


	def __init__(self, path, preload=None, path_is_abs=False):
		if not path_is_abs:
			path = abspath(path)
		self.path = path
		self.basename = basename(path)
		self.basename_lower = self.basename.lower()
		self.extension = splitext(self.basename)[1].lstrip(extsep) or None
		self.dirname = dirname(path)
		self.preload = preload

		try:
			lastdot = self.basename.rindex('.') + 1
			self.extension = self.basename[lastdot:].lower()
		except ValueError:
			self.extension = None

	def __repr__(self):
		return "<{0} {1}>".format(self.__class__.__name__, self.path)

	@lazy_property
	def shell_escaped_basename(self):
		return shell_escape(self.basename)

	@lazy_property
	def filetype(self):
		try:
			return spawn(["file", '-Lb', '--mime-type', self.path])
		except OSError:
			return ""

	@lazy_property
	def basename_natural(self):
		return [int(c) if c.isdigit() else c or 0 \
			for c in _extract_number_re.split(self.basename)]

	@lazy_property
	def basename_natural_lower(self):
		return [int(c) if c.isdigit() else c or 0 \
			for c in _extract_number_re.split(self.basename_lower)]

	def __str__(self):
		"""returns a string containing the absolute path"""
		return str(self.path)

	def use(self):
		"""Used in garbage-collecting.  Override in Directory"""

	def set_mimetype(self):
		"""assign attributes such as self.video according to the mimetype"""
		basename = self.basename
		if self.extension == 'part':
			basename = basename[0:-5]
		self._mimetype = self.fm.mimetypes.guess_type(basename, False)[0]
		if self._mimetype is None:
			self._mimetype = ''

		self.video = self._mimetype.startswith('video')
		self.image = self._mimetype.startswith('image')
		self.audio = self._mimetype.startswith('audio')
		self.media = self.video or self.image or self.audio
		self.document = self._mimetype.startswith('text')
		self.container = self.extension in CONTAINER_EXTENSIONS

		keys = ('video', 'audio', 'image', 'media', 'document', 'container')
		self._mimetype_tuple = tuple(key for key in keys if getattr(self, key))

		if self._mimetype == '':
			self._mimetype = None

	@property
	def mimetype(self):
		try:
			return self._mimetype
		except:
			self.set_mimetype()
			return self._mimetype

	@property
	def mimetype_tuple(self):
		try:
			return self._mimetype_tuple
		except:
			self.set_mimetype()
			return self._mimetype_tuple

	def mark(self, boolean):
		directory = self.env.get_directory(self.dirname)
		directory.mark_item(self)

	def _mark(self, boolean):
		"""Called by directory.mark_item() and similar functions"""
		self.marked = bool(boolean)

	@lazy_property
	def realpath(self):
		if self.is_link:
			try:
				return realpath(self.path)
			except:
				return None  # it is impossible to get the link destination
		return self.path

	def load(self):
		"""
		reads useful information about the filesystem-object from the
		filesystem and caches it for later use
		"""

		self.loaded = True

		# Get the stat object, either from preload or from [l]stat
		new_stat = None
		path = self.path
		is_link = False
		if self.preload:
			new_stat = self.preload[1]
			is_link = new_stat.st_mode & 0o170000 == 0o120000
			if is_link:
				new_stat = self.preload[0]
			self.preload = None
			self.exists = True if new_stat else False
		else:
			try:
				new_stat = lstat(path)
				is_link = new_stat.st_mode & 0o170000 == 0o120000
				if is_link:
					new_stat = stat(path)
				self.exists = True
			except:
				self.exists = False

		# Set some attributes

		self.accessible = True if new_stat else False
		mode = new_stat.st_mode if new_stat else 0

		format = mode & 0o170000
		if format == 0o020000 or format == 0o060000:  # stat.S_IFCHR/BLK
			self.is_device = True
			self.size = 0
			self.infostring = 'dev'
		elif format == 0o010000:  # stat.S_IFIFO
			self.is_fifo = True
			self.size = 0
			self.infostring = 'fifo'
		elif format == 0o140000:  # stat.S_IFSOCK
			self.is_socket = True
			self.size = 0
			self.infostring = 'sock'
		elif self.is_file:
			if new_stat:
				self.size = new_stat.st_size
				self.infostring = ' ' + human_readable(self.size)
			else:
				self.size = 0
				self.infostring = '?'
		elif self.is_directory:
			try:
				self.size = len(listdir(path))  # bite me
			except OSError:
				self.size = 0
				self.infostring = '?'
				self.accessible = False
			else:
				self.infostring = ' %d' % self.size
				self.accessible = True
				self.runnable = True
		if is_link:
			self.infostring = '->' + self.infostring
			self.is_link = True

		self.stat = new_stat

	def get_permission_string(self):
		if self.permissions is not None:
			return self.permissions

		if self.is_directory:
			perms = ['d']
		elif self.is_link:
			perms = ['l']
		else:
			perms = ['-']

		mode = self.stat.st_mode
		test = 0o0400
		while test:  # will run 3 times because 0o400 >> 9 = 0
			for what in "rwx":
				if mode & test:
					perms.append(what)
				else:
					perms.append('-')
				test >>= 1

		self.permissions = ''.join(perms)
		return self.permissions

	def load_if_outdated(self):
		"""
		Calls load() if the currently cached information is outdated
		or nonexistant.
		"""
		if not self.loaded:
			self.load()
			return True
		try:
			real_mtime = lstat(self.path).st_mtime
		except OSError:
			real_mtime = None
		if not self.stat or self.stat.st_mtime != real_mtime:
			self.load()
			return True
		return False