107
107
def _copy_xauthority_file(self, directory):
108
108
""" Copy .Xauthority file to directory, if it exists in /home
110
xauth = os.path.expanduser(os.path.join('~', '.Xauthority'))
110
#If running under xvfb, as jenkins does,
111
#xsession will fail to start without xauthority file
112
#Thus if the Xauthority file is in the home directory
113
#make sure we copy it to our temp home directory
115
xauth = os.path.expanduser(os.path.join(os.environ.get('HOME'),
111
117
if os.path.isfile(xauth):
112
logger.debug("Copying .Xauthority to " + directory)
118
logger.debug("Copying .Xauthority to %s" % directory)
114
os.path.expanduser(os.path.join('~', '.Xauthority')),
120
os.path.expanduser(os.path.join(os.environ.get('HOME'),
115
122
os.path.join(directory, '.Xauthority'))
117
124
def _patch_home(self):
120
127
#click requires apparmor profile, and writing to special dir
121
128
#but the desktop can write to a traditional /tmp directory
122
129
if self.test_type == 'click':
123
temp_dir = os.path.join('~', 'autopilot', 'fakeenv')
124
logger.debug(temp_dir)
125
temp_dir_fixture = fixtures.TempDir(temp_dir)
127
temp_dir_fixture = fixtures.TempDir()
128
self.useFixture(temp_dir_fixture)
129
temp_dir = temp_dir_fixture.path
130
logger.debug(temp_dir)
132
#If running under xvfb, as jenkins does,
133
#xsession will fail to start without xauthority file
134
#Thus if the Xauthority file is in the home directory
135
#make sure we copy it to our temp home directory
136
self._copy_xauthority_file(temp_dir)
138
#click requires using initctl env (upstart), but the desktop can set
139
#an environment variable instead
140
if self.test_type == 'click':
130
env_dir = os.path.join(os.environ.get('HOME'), 'autopilot',
133
if not os.path.exists(env_dir):
136
temp_dir_fixture = fixtures.TempDir(env_dir)
137
self.useFixture(temp_dir_fixture)
139
#apparmor doesn't allow the app to create needed directories,
140
#so we create them now
141
temp_dir = temp_dir_fixture.path
142
temp_dir_cache = os.path.join(temp_dir, '.cache')
143
temp_dir_cache_font = os.path.join(temp_dir_cache, 'fontconfig')
144
temp_dir_cache_media = os.path.join(temp_dir_cache, 'media-art')
145
temp_dir_cache_write = os.path.join(temp_dir_cache,
146
'tncache-write-text.null')
147
temp_dir_config = os.path.join(temp_dir, '.config')
148
temp_dir_toolkit = os.path.join(temp_dir_config,
150
temp_dir_font = os.path.join(temp_dir_cache, '.fontconfig')
151
temp_dir_local = os.path.join(temp_dir, '.local', 'share')
152
temp_dir_confined = os.path.join(temp_dir, 'confined')
154
if not os.path.exists(temp_dir_cache):
155
os.makedirs(temp_dir_cache)
156
if not os.path.exists(temp_dir_cache_font):
157
os.makedirs(temp_dir_cache_font)
158
if not os.path.exists(temp_dir_cache_media):
159
os.makedirs(temp_dir_cache_media)
160
if not os.path.exists(temp_dir_cache_write):
161
os.makedirs(temp_dir_cache_write)
162
if not os.path.exists(temp_dir_config):
163
os.makedirs(temp_dir_config)
164
if not os.path.exists(temp_dir_toolkit):
165
os.makedirs(temp_dir_toolkit)
166
if not os.path.exists(temp_dir_font):
167
os.makedirs(temp_dir_font)
168
if not os.path.exists(temp_dir_local):
169
os.makedirs(temp_dir_local)
170
if not os.path.exists(temp_dir_confined):
171
os.makedirs(temp_dir_confined)
173
#before we set fixture, copy xauthority if needed
174
self._copy_xauthority_file(temp_dir)
141
175
self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
178
temp_dir_fixture = fixtures.TempDir()
179
self.useFixture(temp_dir_fixture)
180
temp_dir = temp_dir_fixture.path
182
#before we set fixture, copy xauthority if needed
183
self._copy_xauthority_file(temp_dir)
144
184
self.useFixture(fixtures.EnvironmentVariable('HOME',
145
185
newvalue=temp_dir))
147
logger.debug("Patched home to fake home directory " + temp_dir)
187
logger.debug("Patched home to fake home directory %s" % temp_dir)