This module helps in interacting with the filesystem. The main focus is on abstracting files and directories and paths.
Path loads Files, Directories, etc. Files have a path associated with them. Directories are a collection of Paths (that link to other files and directories).
There is a circular dependency with these objects, so they need to be kept in one file.
This object holds a summary of a single directory. (no recursion. one level only)
A Directory is a collection of Path objects. They can be sortable based on types, dates, etc. Each of the Paths can handle loading and types.
Directories on the filesystem share many properties with Files, so the Directory class is a subclass of the File class.
adjust the modified time of all files in the directory by the number of hours specified.
#it’s best to just use: jhead -autorot *.JPG
this resets the last modified timestamp to now() not what we want, so go through and reset all timestamps to original times
Go through all files and add up the size.
It is possible to recursively add up sizes of subdirectories, but this can be a resource intensive operation. Be careful when setting recurse=True.
if we don’t have a journal create one using the items of type items
adapted from moments/scripts/images_to_journal.py
usually just want an image but if there are no images, we may want to look for other file types
if we have an action log, use that regardless of pick_by
Not currently configured to work with RemoteJournal
*2010.12.22 06:49:41 seems similar in function to create_journal this is a bit easier to understand from the name though
this is used by /c/moments/scripts/import_usb.py
if we’ve already scanned something once, and a subsequent scan is called, we’ll want to reset ourself so duplicates are not added (common mistake) this is the same thing that happens during initialization, so breaking it out here
only load paths
this will clear out any previous scans to avoid duplication reset includes filetypes and sorts
look in the directory’s list of files for different types of files put them in the right list type in the directory
should have already scanned the directory for files
we will look through the list of files for files that are likely images then populate that list
not sure if this should always happen at scan time what if we don’t need to use images, sounds, movies? extra step maybe only create special node types if they’re needed.
depending on the file extension, should create an object with the appropriate type and add it to the correct list in the Directory
files are Nodes with sizes also leafs in tree structure
could be a file or a directory
one thing connected to other things on the filesystem
structure to hold the meta data of a node on a filesystem should hold the common attributes of files and directories
Node paths are the paths on the local system... i.e. how python would find them
operations common to both files and directories
take new values for the accessed and modified times and update the file’s properties should only accept Timestamp values. Timestamp can be used for conversions as needed. then use Timestamp.epoch() to get right values here:
check and see what the operating system is reporting for this node’s stats update our copy of the stats
object to hold Image specific meta data for an image locally available
and rendering thumbnails
this utilizes the os.rename function but should also move thumbnails
if relative is true, will expect a relative path that is joined with the local path otherwise destination is assumed to be full local path
very similar functionality as minstream.import_media._move_image_and_thumbs() import_media uses subprocess system level move commands which is not as cross platform
rotate image by number of degrees (clockwise!!)
need to reset file timestamp to be original especially if not keeping track of that elsewhere
see also Directory.auto_rotate_images()
but if you need to tune individually, better to call jpegtrans here
jhead -cmd “jpegtran -progressive -rotate 90 &i > &o” IMG_4965.JPG
a path to a specific destination
represented as a string with separators
very similar in purpose to os.path
is not involved with what is contained at the path destination
this is a collection of common operations needed for manipulating paths, in some cases wrapping the standard library os.path module
wrapping os call seems like there was trouble doing this if it crossed devices needed a system call in that case http://docs.python.org/library/shutil.html
see if we have an extension create a blank file if so
otherwise make a new directory
method to change system path to viewer path
if path on file system is different than path displayed by viewer generate it here
ideally would just use routes here... heavy overlap
the shortest number of nodes between self and path
find common prefix then count from there
return a storage.Node of the destination
can look at types here and return the appropriate type
looks at the path, determines the right kind of storage object to associate with that path returns the storage object
walk the given path and create a journal object from all logs encountered in the path
create a temporary, in memory, journal from logs
this works for both directories and log files
*2009.06.18 12:38:45
this was started to be abstracted from osbrowser in player.py. By moving here, we minimize dependencies outside of Moments module
load_journal cannot guarantee that the returned Journal item will have a filename (self.path) associated with it for later saving.
in that case should use:
j = Journal()
j.load(path, add_tags=these_tags)
-or-
j = load_journal(path)
j.path = destination
of course you can always pass the path in explicitly to save: save(filename=path)
this is closely related to journal.log_action (don’t forget to use that if it’s easier)
but sometimes it is inconvenient to think in terms of a journal when you are working with paths
this assumes the journal to log into is “action.txt” if the path is a directory, look for it in the directory if the path is a file (more common) look for action.txt in the parent directory
if logs need to be added anywhere else, use this concept, or journal.log_action
return a Path object to our parent don’t want to do this on initialization, since it would recursively call
Similar in concept to: os.path.dirname(self.path)
return a list of all parts of the path (os.path.split only splits into two parts, this does all)
should work either way... returns the difference between the two paths (self.path and path) return value is just a string representation
accept a path (either Path or path... will get resolved down to str) return the relative part by removing the path sent from our prefix
convert a local file path into one acceptable for use as a relative path in a URL
if node is a file, this will include the filename at the end
looks at the specified path to generate a list of tags based on the file name and location
check if the last item in the path is a file with an extension get rid of the extension if so
take a string (item) and see if any of the strings in ignores list are in the item if so ignore it.
turns out that this is similar to os.path.splitext() but will only return the extension (not both parts)
find a file’s file extension (part of filename after last ‘.’)
splitting into a list with two items: prefix, extension = f.name.split(”.”) will not work with file names with multiple ‘.’s in them