def _copy_into_bundle(self, patterns, dest_dir, exclude_patterns=[]): """copy files and directories described by patterns to dest_dir dest_dir is assumed to be relative to the bundle path """ dest_dir = os.path.normpath(dest_dir).lstrip("/").lstrip("\\") abs_dest_dir = os.path.join(self.path, dest_dir) copied = set() for pattern in patterns: for path in fileutils.glob(pattern): if not fileutils.match_list(path, exclude_patterns): if not pattern.count("**"): basename = os.path.basename(path) fileutils.copy(path, os.path.join(abs_dest_dir, basename), parents=True, replace=True, ignore=fileutils.copy_ignore(exclude_patterns)) copied.add(os.path.join(dest_dir, basename)) else: #strip the fixed portion of the path #we only want to keep the directory structure after the glob expression pattern_segments = fileutils.separate_path(pattern) path_segments = fileutils.separate_path(path) new_root_i = pattern_segments.index("**") dest = os.path.join(abs_dest_dir, *path_segments[new_root_i:]) fileutils.copy(path, dest, parents=True, replace=True, ignore=fileutils.copy_ignore(exclude_patterns)) #to save memory, only the first level after root is added to 'copied' copied.add(os.path.join(dest_dir, *path_segments[new_root_i:new_root_i+1])) return copied
def get(self, dest, options=None): if not options: options = {} if self.source == "@": logging.info("Creating directory {}".format(dest)) fileutils.mkdir(dest, overwrite=options.get("overwrite", False)) return True method = options.get("method", "copy") if method == "copy": logging.info("Copying {} to {}".format(self.source, dest)) fileutils.copy(self.source, dest) elif method == "rsync": logging.info("Rsyncing {} to {}".format(self.source, dest)) fileutils.rsync(self.source, dest) elif method == "link": logging.info("Creating symbolic link {} to {}".format( dest, self.source)) fileutils.link(self.source, dest, overwrite=options.get("overwrite", True)) elif method == "hardlink": logging.info("Creating hard link {} to {}".format( dest, self.source)) fileutils.link(self.source, dest, symbolic=False) return True
def get(self, dest, options=None): if not options: options = {} if self.source == "@": logging.info("Creating directory {}".format(dest)) fileutils.mkdir(dest, overwrite=options.get("overwrite", False)) return True method = options.get("method", "copy") if method == "copy": logging.info("Copying {} to {}".format(self.source, dest)) fileutils.copy(self.source, dest) elif method == "rsync": logging.info("Rsyncing {} to {}".format(self.source, dest)) fileutils.rsync(self.source, dest) elif method == "link": logging.info("Creating symbolic link {} to {}".format(dest, self.source)) fileutils.link(self.source, dest, overwrite=options.get( "overwrite", True)) elif method == "hardlink": logging.info("Creating hard link {} to {}".format(dest, self.source)) fileutils.link(self.source, dest, symbolic=False) return True
def test_rm(self): fileutils.copy(["/etc/hosts"], "/tmp/hosts") fileutils.copy(["/etc/hosts"], "/tmp/hosts2") fileutils.remove(["/tmp/hosts", "/tmp/hosts2"]) f = fileutils.File(self.session(), "/tmp/hosts") self.assertFalse(f.exist) f = fileutils.File(self.session(), "/tmp/hosts2") self.assertFalse(f.exist)
def main(file, bit_depth): f = wave.open(file, 'rb') signal = f.readframes(-1) data = np.fromstring(signal, bit_depth) _len = len(data) rate = f.getframerate() channels = f.getnchannels() compute = True if channels == 1: x = np.linspace(0, rate, _len) yf = fft(data) yf = np.abs(yf) half_y = yf[:int(_len / 2)] half_x = x[:int(_len / 2)] elif channels == 2: x = np.linspace(0, rate, _len / channels) # considering only left data l_data = data[::2] assert (len(l_data) == _len / channels) yf = np.abs(fft(l_data)) assert len(x) == len(yf) half_x = x[:int(_len / channels / 2)] half_y = yf[:int(_len / channels / 2)] else: compute = False print('nothing done') if compute: csv_obj = fs.get_csv_writer('samples/data_fft.csv', 'f', 'a') fft_writer = csv_obj.writer [fft_writer.writerow([f, a]) for f, a in zip(half_x, half_y)] file_base = path.basename(file) file_without_ext, ext = path.splitext(file_base) unique_file_csv = 'samples/data_fft_%s%s' % (file_without_ext, EXT_CSV) csv_obj.fd.close() fs.copy('samples/data_fft.csv', unique_file_csv) print('Saved fft:', unique_file_csv) max_y = max(half_y) csv_obj = fs.get_csv_writer('samples/fundamental_frequencies.csv', 'f', 'a', 'na') writer = csv_obj.writer fft_set = [(f, a, a / max_y) for f, a, in zip(half_x, half_y)] result = [(f, a, na) for f, a, na in fft_set if f < 20000 and na > 0.5] for row in result: writer.writerow(row) freq_unique_file = 'samples/fundamental_frequencies_%s%s' % ( file_without_ext, EXT_CSV) csv_obj.fd.close() fs.copy('samples/fundamental_frequencies.csv', freq_unique_file) print('Saved fundamentals:', freq_unique_file)