/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command/command.py

  • Committer: Tim Marston
  • Date: 2014-03-08 00:40:42 UTC
  • Revision ID: tim@ed.am-20140308004042-j5rco14bjp3teegj
updated .bzrignore

Show diffs side-by-side

added added

removed removed

1
 
# command.py
2
 
#
3
 
# Copyright (C) 2014 Tim Marston <tim@edm.am>
4
 
#
5
 
# This file is part of stdhome (hereafter referred to as "this program").
6
 
# See http://ed.am/dev/stdhome for more information.
7
 
#
8
 
# This program is free software: you can redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as published by
10
 
# the Free Software Foundation, either version 3 of the License, or
11
 
# (at your option) any later version.
12
 
#
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
 
22
 
import os
23
 
import stdhome.the as the
24
 
from stdhome.walker.walker import Walker
25
 
 
26
 
 
27
 
class Command:
28
 
        """Base class for command classes.
29
 
        """
30
 
 
31
 
        @staticmethod
32
 
        def expand_files( files ):
33
 
                """Returns a unique, sorted list of relative files, calculated from the list of
34
 
                files provided, which is made up from individual files and directories
35
 
                to scan that are all relative to the CWD and must be contained within
36
 
                the home directory.
37
 
                """
38
 
 
39
 
                ret = list()
40
 
                home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
41
 
 
42
 
                # iterate through file list
43
 
                for file in files:
44
 
                        abs_file = os.path.realpath( file )
45
 
 
46
 
                        # check the file is in the home directory
47
 
                        if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
48
 
                                raise the.program.FatalError(
49
 
                                        'not in home directory: %s' % abs_file )
50
 
 
51
 
                        # relative file
52
 
                        rel_file = abs_file[ len( home_dir_prefix ) : ]
53
 
 
54
 
                        # check if file exists in repository
55
 
                        repo_file = os.path.join( the.repo.full_dir, rel_file )
56
 
                        if not os.path.lexists( repo_file ):
57
 
                                raise the.program.FatalError(
58
 
                                        'not managed by stdhome: %s' % rel_file )
59
 
 
60
 
                        # append the file or directory tree
61
 
                        ret.extend( Walker.generate_walk_list(
62
 
                                the.repo.full_dir, rel_file ) )
63
 
 
64
 
                return ret