Changeset 469

Show
Ignore:
Timestamp:
05/20/08 09:11:23 (8 months ago)
Author:
jmowery
Message:

incremental check-in for storage: list all layers, collect sub layers, and cli (not fully converted)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/trunk-pmd-intproto/server/storage.py

    r468 r469  
    110110#data gathering functions 
    111111 
    112 #XXX TODO take a look at list_all_layers and collect_layers possibly roll the latter into Layer.list_controlled_dirs() with a recursive parameter 
     112def list_all_layers(path): 
     113        '''Return a list of the group name for all layers in the store including path.''' 
     114        path = os.path.realpath(os.path.expanduser(path)) 
     115        if not os.path.isdir(path): 
     116                path = os.path.dirname(path) 
     117        root_dir = find_control_root(path) 
     118        layer_list = [] 
     119        l = Layer(root_dir) 
     120        layer_list.append(l.name) 
     121        layer_list += collect_layers(l) 
     122        l.update() 
     123        return layer_list 
     124 
     125def collect_layers(l): 
     126        '''Given a layer, return a list of all layers under it (recursively).''' 
     127        layer_list = [] 
     128        for dir in l.list_controlled_dirs(): 
     129                tmp = Layer(os.path.join(l.storage.path, dir)) 
     130                layer_list.append(tmp.name) 
     131                layer_list += collect_layers(tmp) 
     132                tmp.update() 
     133        return layer_list 
    113134 
    114135class Entry: 
     
    10831104        #TODO likely needs more functionality than this 
    10841105 
    1085  
     1106if __name__ == "__main__": 
     1107        #process args and do what is needed as a standalone 
     1108        if len(sys.argv) < 2: 
     1109                print 'missing command' 
     1110                sys.exit(1) 
     1111        if sys.argv[1] == 'help' or sys.argv[1] == 'help+': 
     1112                print 'simple timestamped storage system:' 
     1113                print '' 
     1114                print '  add FILES              Add FILES to the storage system; for directories, only' 
     1115                print '                         add the directory itself not its files.' 
     1116                print '' 
     1117                print '  remove (rm) FILES      Recursively remove FILES from the storage system.' 
     1118                print '' 
     1119                print '  rollback (rb) [TIME]   Roll back the current directory to TIME' 
     1120                print '                         (in seconds since 1970-01-01 00:00:00 UTC).' 
     1121                print '                         If no time is given, use the current system time.' 
     1122                print '' 
     1123                print '  check-in (ci)          Check in all modified files in the current directory' 
     1124                print '                         and its subdirectories.' 
     1125                print '' 
     1126                print '  status (st) [FILES]    Print the status of FILES; if no files are listed,' 
     1127                print '                         print the status of the current directory.' 
     1128                print '' 
     1129                print '  revisions (rev) [FILES]' 
     1130                print '                         Print all revisions of each file in FILES; if no files' 
     1131                print '                         are listed, print the current directory.' 
     1132                print '' 
     1133                print '  lock (lo) [FILES]      Lock FILES preventing change and automatically tracking' 
     1134                print '                         any rollback commands. If no files are listed, lock' 
     1135                print '                         the current directory.' 
     1136                print '' 
     1137                print '  unlock (ul) [FILES]    Unlock FILES locked by the lock command; if not locked,' 
     1138                print '                         this command has no effect on the file. If no files are' 
     1139                print '                         listed, unlock the current directory.' 
     1140                print '' 
     1141                print '  export (ex) PATH       Copy the current version of all files in the current' 
     1142                print '                         directory to the directory PATH' 
     1143                print '' 
     1144                print '  help                   Print this help message.' 
     1145                print '' 
     1146                print '  For all commands other than remove and check-in (which are always recursive),' 
     1147                print '  appending a \'+\' to the command (or its short version) will make it recursive.' 
     1148                sys.exit(0) 
     1149        if sys.argv[1] == 'add': 
     1150                if len(sys.argv) < 3: 
     1151                        print 'missing file(s) to add' 
     1152                        sys.exit(1) 
     1153                for path_name  in sys.argv[2:]: 
     1154                        path = os.path.realpath(os.path.expanduser(path_name)) 
     1155                        if os.path.isdir(path): 
     1156                                l = Layer(path) 
     1157                                l.add('.') 
     1158                                l.update() 
     1159                        else: 
     1160                                layer_name = os.path.dirname(path) 
     1161                                file_name = os.path.basename(path) 
     1162                                l = Layer(layer_name) 
     1163                                l.add(file_name) 
     1164                                l.update() 
     1165        elif sys.argv[1] == 'add+': 
     1166                if len(sys.argv) < 3: 
     1167                        print 'missing file(s) to add' 
     1168                        sys.exit(1) 
     1169                for path_name  in sys.argv[2:]: 
     1170                        path = os.path.realpath(os.path.expanduser(path_name)) 
     1171                        if os.path.isdir(path): 
     1172                                l = Layer(path) 
     1173                                l.add('.', recursive=True) 
     1174                                l.update() 
     1175                        else: 
     1176                                layer_name = os.path.dirname(path) 
     1177                                file_name = os.path.basename(path) 
     1178                                l = Layer(layer_name) 
     1179                                l.add(file_name) 
     1180                                l.update() 
     1181        elif sys.argv[1] == 'remove' or sys.argv[1] == 'rm': 
     1182                if len(sys.argv) < 3: 
     1183                        print 'missing file(s) to remove' 
     1184                        sys.exit(1) 
     1185                for path_name  in sys.argv[2:]: 
     1186                        path = os.path.realpath(os.path.expanduser(path_name)) 
     1187                        if os.path.isdir(path): 
     1188                                l = Layer(path) 
     1189                                l.remove('.') 
     1190                                l.update() 
     1191                        else: 
     1192                                layer_name = os.path.dirname(path) 
     1193                                file_name = os.path.basename(path) 
     1194                                l = Layer(layer_name) 
     1195                                l.remove(file_name) 
     1196                                l.update() 
     1197        elif sys.argv[1] == 'rb+' or sys.argv[1] == 'rollback+': #XXX update me TODO 
     1198                l = Layer(os.getcwd()) 
     1199                if len(sys.argv) < 3: 
     1200                        l.rollback(recursive=True) 
     1201                else: 
     1202                        l.rollback(int(sys.argv[2]), True) 
     1203                l.update() 
     1204        elif sys.argv[1] == 'rb' or sys.argv[1] == 'rollback': #XXX update me TODO 
     1205                l = Layer(os.getcwd()) 
     1206                if len(sys.argv) < 3: 
     1207                        l.rollback(recursive=False) 
     1208                else: 
     1209                        l.rollback(int(sys.argv[2]), False) 
     1210                l.update() 
     1211        elif sys.argv[1] == 'status' or sys.argv[1] == 'st': #XXX update me TODO 
     1212                if len(sys.argv) < 3: 
     1213                        l = Layer(os.getcwd()) 
     1214                        l.print_status() 
     1215                else: 
     1216                        for path_name  in sys.argv[2:]: 
     1217                                prefix = os.path.dirname(path_name) 
     1218                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1219                                if os.path.isdir(path): 
     1220                                        l = Layer(path) 
     1221                                        l.print_status('.') 
     1222                                else: 
     1223                                        layer_name = os.path.dirname(path) 
     1224                                        file_name = os.path.basename(path) 
     1225                                        l = Layer(layer_name) 
     1226                                        l.print_status(file_name, prefix=prefix) 
     1227        elif sys.argv[1] == 'status+' or sys.argv[1] == 'st+': #XXX update me TODO 
     1228                if len(sys.argv) < 3: 
     1229                        l = Layer(os.getcwd()) 
     1230                        l.print_status(recursive=True) 
     1231                else: 
     1232                        for path_name  in sys.argv[2:]: 
     1233                                prefix = os.path.dirname(path_name) 
     1234                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1235                                if os.path.isdir(path): 
     1236                                        l = Layer(path) 
     1237                                        l.print_status('.', True) 
     1238                                else: 
     1239                                        layer_name = os.path.dirname(path) 
     1240                                        file_name = os.path.basename(path) 
     1241                                        l = Layer(layer_name) 
     1242                                        l.print_status(file_name, prefix=prefix) 
     1243        elif sys.argv[1] == 'check-in' or sys.argv[1] == 'ci': 
     1244                l = Layer(os.getcwd()) 
     1245                l.checkin() 
     1246        elif sys.argv[1] == 'revisions' or sys.argv[1] == 'rev': #XXX update me TODO 
     1247                if len(sys.argv) < 3: 
     1248                        l = Layer(os.getcwd()) 
     1249                        l.print_revisions() 
     1250                else: 
     1251                        for path_name  in sys.argv[2:]: 
     1252                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1253                                if os.path.isdir(path): 
     1254                                        l = Layer(path) 
     1255                                        l.print_revisions('.') 
     1256                                else: 
     1257                                        layer_name = os.path.dirname(path) 
     1258                                        file_name = os.path.basename(path) 
     1259                                        l = Layer(layer_name) 
     1260                                        l.print_revisions(file_name) 
     1261        elif sys.argv[1] == 'revisions+' or sys.argv[1] == 'rev+': #XXX update me TODO 
     1262                if len(sys.argv) < 3: 
     1263                        l = Layer(os.getcwd()) 
     1264                        l.print_revisions(recursive=True) 
     1265                else: 
     1266                        for path_name  in sys.argv[2:]: 
     1267                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1268                                if os.path.isdir(path): 
     1269                                        l = Layer(path) 
     1270                                        l.print_revisions('.', True) 
     1271                                else: 
     1272                                        layer_name = os.path.dirname(path) 
     1273                                        file_name = os.path.basename(path) 
     1274                                        l = Layer(layer_name) 
     1275                                        l.print_revisions(file_name) 
     1276        elif sys.argv[1] == 'lock' or sys.argv[1] == 'lo': 
     1277                if len(sys.argv) < 3: 
     1278                        l = Layer(os.getcwd()) 
     1279                        l.lock() 
     1280                        l.update() 
     1281                else: 
     1282                        for path_name  in sys.argv[2:]: 
     1283                                prefix = os.path.dirname(path_name) 
     1284                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1285                                if os.path.isdir(path): 
     1286                                        l = Layer(path) 
     1287                                        l.lock('.') 
     1288                                        l.update() 
     1289                                else: 
     1290                                        layer_name = os.path.dirname(path) 
     1291                                        file_name = os.path.basename(path) 
     1292                                        l = Layer(layer_name) 
     1293                                        l.lock(file_name) 
     1294                                        l.update() 
     1295        elif sys.argv[1] == 'lock+' or sys.argv[1] == 'lo+': 
     1296                if len(sys.argv) < 3: 
     1297                        l = Layer(os.getcwd()) 
     1298                        l.lock(recursive=True) 
     1299                        l.update() 
     1300                else: 
     1301                        for path_name  in sys.argv[2:]: 
     1302                                prefix = os.path.dirname(path_name) 
     1303                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1304                                if os.path.isdir(path): 
     1305                                        l = Layer(path) 
     1306                                        l.lock('.', True) 
     1307                                        l.update() 
     1308                                else: 
     1309                                        layer_name = os.path.dirname(path) 
     1310                                        file_name = os.path.basename(path) 
     1311                                        l = Layer(layer_name) 
     1312                                        l.lock(file_name) 
     1313                                        l.update() 
     1314        elif sys.argv[1] == 'unlock' or sys.argv[1] == 'ul': 
     1315                if len(sys.argv) < 3: 
     1316                        l = Layer(os.getcwd()) 
     1317                        l.unlock() 
     1318                        l.update() 
     1319                else: 
     1320                        for path_name  in sys.argv[2:]: 
     1321                                prefix = os.path.dirname(path_name) 
     1322                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1323                                if os.path.isdir(path): 
     1324                                        l = Layer(path) 
     1325                                        l.unlock('.') 
     1326                                        l.update() 
     1327                                else: 
     1328                                        layer_name = os.path.dirname(path) 
     1329                                        file_name = os.path.basename(path) 
     1330                                        l = Layer(layer_name) 
     1331                                        l.unlock(file_name) 
     1332                                        l.update() 
     1333        elif sys.argv[1] == 'unlock+' or sys.argv[1] == 'ul+': 
     1334                if len(sys.argv) < 3: 
     1335                        l = Layer(os.getcwd()) 
     1336                        l.unlock(recursive=True) 
     1337                        l.update() 
     1338                else: 
     1339                        for path_name  in sys.argv[2:]: 
     1340                                prefix = os.path.dirname(path_name) 
     1341                                path = os.path.realpath(os.path.expanduser(path_name)) 
     1342                                if os.path.isdir(path): 
     1343                                        l = Layer(path) 
     1344                                        l.unlock('.', True) 
     1345                                        l.update() 
     1346                                else: 
     1347                                        layer_name = os.path.dirname(path) 
     1348                                        file_name = os.path.basename(path) 
     1349                                        l = Layer(layer_name) 
     1350                                        l.unlock(file_name) 
     1351                                        l.update() 
     1352        elif sys.argv[1] == 'export' or sys.argv[1] == 'ex': 
     1353                l = Layer(os.getcwd()) 
     1354                if len (sys.argv) < 3: 
     1355                        print 'missing destination path' 
     1356                        sys.exit(1) 
     1357                l.export(sys.argv[2]) 
     1358        else: 
     1359                print 'unrecognized command \'' + sys.argv[1] + '\'' 
     1360                sys.exit(1) 
     1361 
     1362