~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to ubuntuone/u1sync/utils.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-02-11 16:18:11 UTC
  • mto: This revision was merged to the branch mainline in revision 67.
  • Revision ID: james.westby@ubuntu.com-20110211161811-n18dj9lde7dxqjzr
Tags: upstream-1.5.4
ImportĀ upstreamĀ versionĀ 1.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ubuntuone.u1sync.utils
2
 
#
3
 
# Miscellaneous utility functions
4
 
#
5
 
# Author: Tim Cole <tim.cole@canonical.com>
6
 
#
7
 
# Copyright 2009 Canonical Ltd.
8
 
#
9
 
# This program is free software: you can redistribute it and/or modify it
10
 
# under the terms of the GNU General Public License version 3, as published
11
 
# by the Free Software Foundation.
12
 
#
13
 
# This program is distributed in the hope that it will be useful, but
14
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
15
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16
 
# PURPOSE.  See the GNU General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License along
19
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
"""Miscellaneous utility functions."""
21
 
 
22
 
from errno import EEXIST, ENOENT
23
 
from ubuntuone.u1sync.constants import (
24
 
    METADATA_DIR_NAME, SPECIAL_FILE_RE)
25
 
 
26
 
from ubuntuone.platform import (
27
 
    remove_file,
28
 
    make_dir,
29
 
)
30
 
 
31
 
def should_sync(filename):
32
 
    """Returns True if the filename should be synced.
33
 
 
34
 
    @param filename: a unicode filename
35
 
 
36
 
    """
37
 
    return filename != METADATA_DIR_NAME and \
38
 
           not SPECIAL_FILE_RE.match(filename)
39
 
 
40
 
def safe_mkdir(path):
41
 
    """Creates a directory if it does not already exist."""
42
 
    try:
43
 
        make_dir(path)
44
 
    except OSError, e:
45
 
        if e.errno != EEXIST:
46
 
            raise
47
 
 
48
 
def safe_unlink(path):
49
 
    """Unlinks a file if it exists."""
50
 
    try:
51
 
        remove_file(path)
52
 
    except OSError, e:
53
 
        if e.errno != ENOENT:
54
 
            raise