def main(argc, argv): options = Options(argv) if options.version: sys.stderr.write("%s\n" % __version__) return 1 if options.help or len(options.arg) < 1: usage() return 1 if options.debug: LogLevel.enableDebug() if options.copy: if len(options.arg) < 2: usage() return 1 filename = options.arg[0] config = ClientConfiguration(options.config) if options.config: if not config.read(options.config): error("cannot read config file %s. using build-in defaults" % options.config) else: if not config.loadDefault(): error("cannot read default config file. using build-in defaults") if options.nobundle: config.IGNORE_BUNDLE = True if options.printDestination: print CmClient.getDestination(FileSystem(config), os.path.realpath(filename)) return 0 client = CmClient(config) if not client.isConnected(): error("cannot connect to server") else: log("connected to %s" % str(client.connection.getPeerName())) r = False if options.copy: r = client.copy(filename, options.arg[1], options.register, options.bundle) elif options.locate: locations = [] r = client.getLocations(options.arg, locations, options.bundle) log("%d locations found" % len(locations)) for l in locations: print "%s:%s:%s" % l else: f, r = client.fetch(filename, options.bundle, options.conjunct) print f return not r
def copyFile(source, destination, verbose=True): """convenience function to copy a file from the local disk to a file server. returns true if the file was copied. """ loglevel = LogLevel.level if not verbose: LogLevel.level = 0 config = ClientConfiguration() config.loadDefault() client = CmClient(config) ok = client.copy(source, destination) LogLevel.set(loglevel) return ok
def cacheFile(filename, verbose=True): """convenience function to cache a file to the local disk. returns the path of the cached file. """ loglevel = LogLevel.level if not verbose: LogLevel.level = 0 config = ClientConfiguration() config.loadDefault() client = CmClient(config) cachedFile, ok = client.fetch(filename) LogLevel.set(loglevel) return cachedFile