/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: 2016-04-10 20:29:46 UTC
  • Revision ID: tim@ed.am-20160410202946-9eoh5i3et9443aq6
fixed greps in tools/dev to detect home-dir lines in stdhomerc

Show diffs side-by-side

added added

removed removed

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