~ubuntu-branches/ubuntu/saucy/deja-dup/saucy

« back to all changes in this revision

Viewing changes to common/CommonUtils.vala

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-05 13:45:39 UTC
  • mfrom: (1.1.43)
  • Revision ID: package-import@ubuntu.com-20120605134539-l35tewhkjfq4qp6e
Tags: 23.2-0ubuntu1
* New upstream release
* debian/control:
  - Add libpeas-dev to Build-Depends
  - Update valac and libglib2.0-dev versions
  - Bump debhelper version to 9
* debian/compat:
  - Bump to 9
* debian/rules:
  - Don't install new .la and .a files from upstream
* debian/patches/allow-resuming-encrypted-backup.patch:
  - Dropped, included upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
228
228
  settings.set_string(PROMPT_CHECK_KEY, cur_time_str);
229
229
}
230
230
 
231
 
public string get_trash_path()
232
 
{
233
 
  return Path.build_filename(Environment.get_user_data_dir(), "Trash");
234
 
}
235
 
 
236
231
public string get_folder_key(SimpleSettings settings, string key)
237
232
{
238
233
  string folder = settings.get_string(key);
245
240
  return folder;
246
241
}
247
242
 
248
 
public File? parse_dir(string dir)
249
 
{
250
 
  string s = dir;
251
 
  if (s == "$HOME")
252
 
    s = Environment.get_home_dir();
253
 
  else if (s == "$DESKTOP")
254
 
    s = Environment.get_user_special_dir(UserDirectory.DESKTOP);
255
 
  else if (s == "$DOCUMENTS")
256
 
    s = Environment.get_user_special_dir(UserDirectory.DOCUMENTS);
257
 
  else if (s == "$DOWNLOAD")
258
 
    s = Environment.get_user_special_dir(UserDirectory.DOWNLOAD);
259
 
  else if (s == "$MUSIC")
260
 
    s = Environment.get_user_special_dir(UserDirectory.MUSIC);
261
 
  else if (s == "$PICTURES")
262
 
    s = Environment.get_user_special_dir(UserDirectory.PICTURES);
263
 
  else if (s == "$PUBLIC_SHARE")
264
 
    s = Environment.get_user_special_dir(UserDirectory.PUBLIC_SHARE);
265
 
  else if (s == "$TEMPLATES")
266
 
    s = Environment.get_user_special_dir(UserDirectory.TEMPLATES);
267
 
  else if (s == "$TRASH")
268
 
    s = get_trash_path();
269
 
  else if (s == "$VIDEOS")
270
 
    s = Environment.get_user_special_dir(UserDirectory.VIDEOS);
271
 
  else if (Uri.parse_scheme(s) == null && !Path.is_absolute(s))
272
 
    s = Path.build_filename(Environment.get_home_dir(), s);
273
 
  else
274
 
    return File.parse_name(s);
275
 
 
276
 
  if (s != null)
277
 
    return File.new_for_path(s);
278
 
  else
279
 
    return null;
280
 
}
281
 
 
282
 
public File[] parse_dir_list(string*[] dirs)
283
 
{
284
 
  File[] rv = new File[0];
285
 
  
286
 
  foreach (string s in dirs) {
287
 
    var f = parse_dir(s);
288
 
    if (f != null)
289
 
      rv += f;
290
 
  }
291
 
  
292
 
  return rv;
293
 
}
294
 
 
295
243
bool settings_read_only = false;
296
244
HashTable<string, SimpleSettings> settings_table = null;
297
245
public void set_settings_read_only(bool ro)
389
337
  }
390
338
}
391
339
 
392
 
public bool meet_requirements(out string header, out string msg)
393
 
{
394
 
  return DuplicityInfo.get_default().check_duplicity_version(out header, out msg);
 
340
ToolPlugin tool = null;
 
341
void initialize_tool_plugin() throws Error
 
342
{
 
343
  var engine = new Peas.Engine ();
 
344
 
 
345
  // For testing, we'll often point to in-tree tools
 
346
  string search_path = Environment.get_variable("DEJA_DUP_TOOLS_PATH");
 
347
  if (search_path == null || search_path == "")
 
348
    search_path = Path.build_filename(Config.PKG_LIBEXEC_DIR, "tools");
 
349
  engine.add_search_path(search_path, null);
 
350
 
 
351
  var info = engine.get_plugin_info("libduplicity.so");
 
352
  if (info == null)
 
353
    throw new SpawnError.FAILED(_("Could not find backup tool in %s.  Your installation is incomplete.").printf(search_path));
 
354
  if (!engine.try_load_plugin(info))
 
355
    throw new SpawnError.FAILED(_("Could not load backup tool.  Your installation is incomplete."));
 
356
 
 
357
  var extset = new Peas.ExtensionSet(engine, typeof(Peas.Activatable));
 
358
  var ext = extset.get_extension(info);
 
359
  tool = ext as ToolPlugin;
 
360
  if (tool == null)
 
361
    throw new SpawnError.FAILED(_("Backup tool is broken.  Your installation is incomplete."));
 
362
 
 
363
  tool.activate();
 
364
}
 
365
 
 
366
public ToolJob make_tool_job() throws Error
 
367
{
 
368
  if (tool == null)
 
369
    initialize_tool_plugin();
 
370
  return tool.create_job();
395
371
}
396
372
 
397
373
public bool initialize(out string header, out string msg)
398
374
{
399
 
  if (!meet_requirements(out header, out msg))
 
375
  header = null;
 
376
  msg = null;
 
377
 
 
378
  // Get tool plugin to use
 
379
  try {
 
380
    initialize_tool_plugin();
 
381
  }
 
382
  catch (Error e) {
 
383
    header = _("Could not start backup tool");
 
384
    msg = e.message;
400
385
    return false;
 
386
  }
401
387
 
402
388
  convert_ssh_to_file();
403
389
  convert_s3_folder_to_hostname();
430
416
{
431
417
  // First try to get the DESCRIPTION.  Else get the DISPLAY_NAME
432
418
  try {
433
 
    var info = file.query_info(FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + "," +
434
 
                               FILE_ATTRIBUTE_STANDARD_DESCRIPTION,
 
419
    var info = file.query_info(FileAttribute.STANDARD_DISPLAY_NAME + "," +
 
420
                               FileAttribute.STANDARD_DESCRIPTION,
435
421
                               FileQueryInfoFlags.NONE, null);
436
 
    if (info.has_attribute(FILE_ATTRIBUTE_STANDARD_DESCRIPTION))
437
 
      return info.get_attribute_string(FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
438
 
    else if (info.has_attribute(FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME))
439
 
      return info.get_attribute_string(FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
 
422
    if (info.has_attribute(FileAttribute.STANDARD_DESCRIPTION))
 
423
      return info.get_attribute_string(FileAttribute.STANDARD_DESCRIPTION);
 
424
    else if (info.has_attribute(FileAttribute.STANDARD_DISPLAY_NAME))
 
425
      return info.get_attribute_string(FileAttribute.STANDARD_DISPLAY_NAME);
440
426
  }
441
427
  catch (Error e) {}
442
428
 
492
478
    // were backing up more than they were.  This should help avoid such data
493
479
    // loss accidents.
494
480
    try {
495
 
      var info = yield f.query_info_async(FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
 
481
      var info = yield f.query_info_async(FileAttribute.STANDARD_DISPLAY_NAME,
496
482
                                          FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
497
483
      // Translators: this is the home folder and %s is the user's username
498
484
      s = _("Home (%s)").printf(info.get_display_name());