Esempio n. 1
0
def is_network_volume(share_path):
    '''NSWorkspace alows us to check for filesystem type of a specified path'''
    #pylint: disable=C0301,C0103
    ws = NSWorkspace.alloc().init()
    share_type = ws.getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type_(
        share_path, None, None, None, None, None)[-1]
    return True if share_type == 'smbfs' or share_type == 'webdav' else False
Esempio n. 2
0
def doDownload(destinationPaths,
               tag,
               description,
               delete=False,
               verbose=False):

    # Find the source volume.  We can only handle one.
    sourceVols = findSourceVolume()
    if (len(sourceVols) < 1):
        raise CLIError("Could not find a DCF volume.")
    if (len(sourceVols) > 1):
        raise CLIError("More than one DCF volume found.")
    sourceVol = sourceVols[0]

    # Find image files on the source volume.
    images = findSourceImages(sourceVol[1])
    print("{0} image files found on {1}.".format(len(images), sourceVol[0]))

    # If we're supposed to delete the source images, make sure that we can.
    if (delete and not os.access(sourceVol[1], os.W_OK)):
        raise CLIError

    # Handle multiple possible destinations.
    # DestinationDirs and duplicates are lists in the same order as the
    # entries in destinationPaths.
    destinationDirs = []
    duplicates = []
    today = datetime.date.today()
    dirName = str(today.month) + "-" + str(today.day) + " " + tag
    for destPath in destinationPaths:

        # Create the destination directory, if necessary.
        destDir = createDestinationDir(destPath, dirName)
        destinationDirs.append(destDir)

        # Look for duplicate image files on the destination.
        dups = lookForDuplicates(images, destDir)
        duplicates.append(dups)
        if len(dups) > 0:
            print("%d image files already exist in \"%s\". " %
                  (len(dups), destDir))

    # Copy the image files from the source to the destinations and create the sidecar files.
    copyImageFiles(images, destinationDirs, duplicates, description, delete)

    # Delete the source files.
    if delete:
        print("Deleting images from {0}.\n".format(sourceVol[0]))
        shutil.rmtree(sourceVol[1])

    # Request the Finder to eject the source volume.

    if 'darwin' in sys.platform:
        for attempt in range(1, 20):
            workspace = NSWorkspace.alloc()
            ejected = workspace.unmountAndEjectDeviceAtPath_(
                os.path.join("/Volumes", sourceVol[0]))
            if ejected:
                break
            print("Attempting to eject {0}...".format(sourceVol[0]))
            time.sleep(1)
            if ejected:
                print("All images successfully downloaded and {0} ejected.".
                      format(sourceVol[0]))
            else:
                print(
                    "ERROR - All images successfully downloaded, but could not eject {0}!"
                    .format(sourceVol[0]))
    else:
        print("All images successfully downloaded.")

    return dirName