[xiph-cvs] cvs commit: positron/positron neuros.py ports.py
Stan Seibert
volsung at xiph.org
Sun May 25 14:05:51 PDT 2003
volsung 03/05/25 17:05:51
Modified: positron neuros.py ports.py
Log:
Detect (based on size) whether the flash memory or the HD backpack is being
used and make the root drive D: or C: (respectively). Fixes bug #354.
Special thanks to matthias at utdallas.edu for spotting this error and
finding a fix.
Revision Changes Path
1.3 +42 -4 positron/positron/neuros.py
Index: neuros.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/neuros.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- neuros.py 24 May 2003 19:29:09 -0000 1.2
+++ neuros.py 25 May 2003 21:05:51 -0000 1.3
@@ -19,6 +19,7 @@
import os
from os import path
import util
+import ports
class Error(Exception):
"""Base class for exceptions in this module."""
@@ -67,6 +68,12 @@
DB_DIR = path.normcase("WOID_DB")
+ # Constants for describing the type of Neuros
+ TYPE_UNKNOWN = 0
+ TYPE_FLASH = 1
+ TYPE_HD = 2
+
+
db_formats = {
"audio" : { "no_flatten" : (1, ),
"extra_format" : (">I",">I","z"),
@@ -111,6 +118,26 @@
for db_name in self.db_formats.keys():
self.db[db_name] = None
+ # Figure out what kind of Neuros this is
+ (self.neuros_type, self.neuros_size) = self._detect_neuros_type(self.mountpoint)
+
+
+ def _detect_neuros_type(self, mountpoint):
+
+ # There is no direct way to determine the type of Neuros
+ # (either flash or HD) so we have to infer it from the size of
+ # the volumes connected to the system.
+
+ size = ports.filesystem_size(mountpoint)
+
+ if size == None:
+ return (Neuros.TYPE_UNKNOWN, -1)
+ elif size < 2147483648: # Use 2 GB as an arbitrary size cutoff
+ return (Neuros.TYPE_FLASH, size)
+ else:
+ return (Neuros.TYPE_HD, size)
+
+
def open_db(self, name):
if name not in self.db.keys():
@@ -174,23 +201,34 @@
return self.mountpoint_parts == \
hostpath_parts[:len(self.mountpoint_parts)]
- def hostpath_to_neurospath(self, hostpath):
+ def hostpath_to_neurospath(self, hostpath, neuros_type = None):
if not self.is_valid_hostpath(hostpath):
raise Error("Host path not under Neuros mountpoint")
# Get the path parts, but prune off the mountpoint
hostpath_parts = _total_path_split(hostpath)[len(self.mountpoint_parts):]
- hostpath_parts.insert(0,"C:")
+ if neuros_type == None:
+ neuros_type = self.neuros_type
+ if neuros_type == Neuros.TYPE_HD:
+ drive_letter = "C:"
+ elif neuros_type == Neuros.TYPE_FLASH:
+ drive_letter = "D:"
+ else:
+ # Assume HD
+ drive_letter = "C:"
+
+ hostpath_parts.insert(0, drive_letter)
# Now join it all with forward slashes to get the Neuros path
return "/".join(hostpath_parts)
def neurospath_to_hostpath(self, neurospath):
neurospath_parts = neurospath.split("/")
- if len(neurospath_parts) < 1 or neurospath_parts[0].lower() != "c:":
- raise Error("Neuros path does not start with C:")
+ if len(neurospath_parts) < 1 \
+ or neurospath_parts[0].lower() not in ("c:", "d:"):
+ raise Error("Neuros path does not start with C: or D:")
hostpath_parts = self.mountpoint_parts + neurospath_parts[1:]
<p><p>1.2 +19 -1 positron/positron/ports.py
Index: ports.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/ports.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ports.py 22 May 2003 04:42:52 -0000 1.1
+++ ports.py 25 May 2003 21:05:51 -0000 1.2
@@ -14,10 +14,28 @@
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
+import sys
import os
from os import path
+from util import trim_newline
# Someday we'll stick OS specific information into this file
def user_config_dir():
- return path.join(path.expanduser("~"),".positron")
+ return path.join(path.expanduser("~"),".positron")
+
+def filesystem_size(pathname):
+ """Returns the size of the filesystem where pathname is stored in bytes.
+
+ Returns None, if the size cannot be found for whatever reason."""
+
+ if sys.platform[:3] == "win":
+ size = None
+ else:
+ try:
+ stat = os.statvfs(pathname)
+ size = stat.f_bsize * stat.f_blocks
+ except Exception:
+ pass
+
+ return size
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list