def set_file_properties(self, filename, timestamp, filesize, md5): """ Set properties of the given file in the repo cache """ # Due to a bug in PYYAML, we cannot serialise/deserialise time-zone aware timecodes # correctly. Save them as a string instead. abs_file = os.path.abspath( os.path.join(self._root, filename) ); utils.set_timestamp_on_file(abs_file, timestamp) str_timestamp = str(timestamp) self._cfg["files"][filename] = [str_timestamp, filesize, md5]
def download(self, remote_file, local_file, set_timestamp=True, verbose=True): """ Download a file from the bucket to the given local file path, and @return some relevent file properties """ global i ctr = ["-", "\\", "|", "/"] i = 0 def callback(uploaded, total_size): global i i = (i + 1) % len(ctr) c = ctr[i] if total_size == 0: pct = 100 else: pct = (uploaded / float(total_size)) * 100 sys.stdout.write( "\r <- [%d KB] %d / %d (%d%s) %s" % (total_size / 1024, uploaded, total_size, pct, "%", c)) sys.stdout.flush() if not verbose: callback = None path, filen = os.path.split(local_file) if not os.path.exists(path) and len(path.strip()) > 0: os.makedirs(path) key = self._bucket.get_key(remote_file) key.get_contents_to_filename(local_file, cb=callback) print "" if set_timestamp: modified_date = utils.parse_iso_date(key.last_modified) utils.set_timestamp_on_file(local_file, modified_date) return [key.last_modified, key.size, key.md5] ###############################################################################################
def download(self, remote_file, local_file, set_timestamp=True, verbose=True): """ Download a file from the bucket to the given local file path, and @return some relevent file properties """ global i ctr = ["-", "\\", "|", "/"] i = 0 def callback(uploaded, total_size): global i i = (i + 1) % len(ctr) c = ctr[i] if total_size == 0: pct = 100 else: pct = (uploaded/float(total_size))*100 sys.stdout.write( "\r <- [%d KB] %d / %d (%d%s) %s" % (total_size/1024, uploaded, total_size, pct, "%", c) ) sys.stdout.flush() if not verbose: callback = None path, filen = os.path.split(local_file) if not os.path.exists(path) and len(path.strip()) > 0: os.makedirs(path); key = self._bucket.get_key(remote_file) key.get_contents_to_filename(local_file, cb=callback); print "" if set_timestamp: modified_date = utils.parse_iso_date(key.last_modified) utils.set_timestamp_on_file(local_file, modified_date) return [key.last_modified, key.size, key.md5] ###############################################################################################