/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/add.py

  • Committer: Tim Marston
  • Date: 2014-04-18 15:00:34 UTC
  • Revision ID: tim@ed.am-20140418150034-l94wfs6ururhi9t5
fixed error in walker.py (from last checkin)

Show diffs side-by-side

added added

removed removed

53
53
                        [ "repo=", "verbose", "help" ] )
54
54
                for opt, optarg in opts:
55
55
                        if opt in [ '--repo', '-r' ]:
56
 
                                if not re.search( '^[-a-zA-z0-9.]+$', optarg ):
 
56
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
57
57
                                        raise the.program.FatalError(
58
58
                                                'invalid repository name: ' + optarg )
59
59
                                the.repo = optarg
 
60
                        elif opt in [ '--verbose', '-v' ]:
 
61
                                the.verbose += 1
60
62
                        elif opt == "--help":
61
63
                                self.print_help()
62
 
 
 
64
                
63
65
                # discard first argument (the command)
64
66
                args.pop( 0 )
65
67
 
87
89
                if the.repo.vcs.has_changes():
88
90
                        raise the.program.FatalError(
89
91
                                'repo has local changes: %s\n'
90
 
                                'Hint: see "%s stage-revert --help"' %
 
92
                                'Hint: see "%s stage-revert --help"' % 
91
93
                                ( the.repo.name, the.program.name ) )
92
94
 
93
95
                # check status
107
109
        def expand_home_dir_files( files ):
108
110
                """Returns a unique, sorted list of relative filenames, calculated from the list
109
111
                provided, which is made up from individual files and directories
110
 
                relative to the CWD.  Directories and are not recursed in to, but
111
 
                leading path components are also returned.  Specified filenames must
112
 
                exist in the home directory (although they may not exist in the repo).
113
 
 
 
112
                relative to the CWD.  Directories and are not recursed in to.  Specified
 
113
                filenames must exist in the home directory (although they may not exist
 
114
                in the repo).
114
115
                """
115
116
 
116
 
                ret = set()
 
117
                ret = list()
117
118
                home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
118
119
 
119
120
                # iterate through file list
125
126
                        # check the file is in the home directory
126
127
                        if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
127
128
                                raise the.program.FatalError(
128
 
                                        'not under home directory: %s' % abs_file )
 
129
                                        'not in home directory: %s' % abs_file )
129
130
 
130
131
                        # relative file
131
132
                        rel_file = abs_file[ len( home_dir_prefix ) : ]
133
134
                        # check if file exists in home directory
134
135
                        if not os.path.lexists( abs_file ):
135
136
                                raise the.program.FatalError(
136
 
                                        'not found in home directory: %s' % rel_file )
137
 
 
138
 
                        # append path parts
139
 
                        path = rel_file
140
 
                        while True:
141
 
                                path, dummy = os.path.split( path )
142
 
                                if len( path ): ret.add( path )
143
 
                                else: break
144
 
 
145
 
                        # append the file or directory
146
 
                        ret.add( rel_file )
147
 
 
148
 
                return sorted( ret )
 
137
                                        'not in home directory: %s' % rel_file )
 
138
 
 
139
                        # append the file or directory tree
 
140
                        ret.append( rel_file )
 
141
 
 
142
                return sorted( set ( ret ) )