~canonical-platform-qa/ubuntu-system-tests/use_keyboard_reset_lp1481770

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/file_system.py

Three test cases implemented:
 . Copy to ubuntu host from sd card through mtp
 . Copy to sd card from ubuntu host to through mtp
 . Check There is one entry per inode.

Approved by Richard Huddie, PS Jenkins bot, Brendan Donegan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import filecmp
22
22
import getpass
 
23
import glob
23
24
import hashlib
24
25
import logging
25
26
import random
56
57
DIR_TEST_DATA_VIDEO = os.path.join(DIR_TEST_DATA, 'video')
57
58
 
58
59
DIR_TEMP = '/tmp'
 
60
DIR_MEDIA = '/media'
 
61
DIR_MEDIA_ROOT = os.path.join(DIR_MEDIA, getpass.getuser())
59
62
 
60
63
 
61
64
def delete_file(file_name):
142
145
    return directories
143
146
 
144
147
 
 
148
def is_media_folder_dir(media_dir):
 
149
    """
 
150
    Indicate if the media dir exists or not
 
151
    :param media_dir: The media dir required such as: Music, Videos, etc
 
152
    :return: True if the media dir exists and False otherwise
 
153
    """
 
154
    try:
 
155
        get_media_folder_dir(media_dir)
 
156
        return True
 
157
    except RuntimeError:
 
158
        return False
 
159
 
 
160
 
 
161
def get_media_folder_dir(media_dir):
 
162
    """Get the first media folders that matches with the media dir passed as
 
163
    parameter.
 
164
    :param media_dir: The media dir required such as: Music, Videos, etc
 
165
    :return: The path to the media path
 
166
    :raises: RuntimeError: when the media dir does not exist
 
167
    """
 
168
    if not os.path.isdir(DIR_MEDIA_ROOT):
 
169
        raise RuntimeError('Media directory does not exist: ' + DIR_MEDIA_ROOT)
 
170
 
 
171
    media_dirs = glob.glob(DIR_MEDIA_ROOT + '/*/{name}'.format(name=media_dir))
 
172
    if not media_dirs:
 
173
        raise RuntimeError('Media directory does not exist.')
 
174
 
 
175
    return media_dirs[0]
 
176
 
 
177
 
145
178
def _get_media_folders_for_home_folder():
146
179
    """Get media folders from home folder."""
147
180
    return _get_media_folders_from_root(DIR_HOME)
150
183
def _get_media_folders_for_media_devices():
151
184
    """Get media directories for any storage devices present."""
152
185
    directories = []
153
 
    media_root = '/media/{u}'.format(u=getpass.getuser())
154
 
    if os.path.exists(media_root):
155
 
        for directory in os.listdir(media_root):
 
186
    if os.path.exists(DIR_MEDIA_ROOT):
 
187
        for directory in os.listdir(DIR_MEDIA_ROOT):
156
188
            media_directory = os.path.abspath(
157
 
                os.path.join(media_root, directory))
 
189
                os.path.join(DIR_MEDIA_ROOT, directory))
158
190
            directories += _get_media_folders_from_root(media_directory)
159
191
    return directories
160
192