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 remove_non_actual_files(self): if not fileutils.isdir(self.out_directory): return files = fileutils.get_files_list(self.out_directory) for filename in files: if self.out_directory + filename not in self.created_files: if not filename.endswith('.pyc'): Log.debug(' Removed: {}'.format(filename)) fileutils.remove(self.out_directory + filename)
def extract(filepath, dest, verbose=False): """ Extract an archive using the appropriate system commands """ args_7z = ["x", "-y", "-o" + dest] try: if os.path.splitext(filepath)[0].endswith(".tar") or filepath.endswith(".tgz"): if os_name() == "win": run_cmd("7z", args_7z + [filepath], not verbose) tar_filepath = os.path.join(dest, os.listdir(dest)[0]) run_cmd("7z", args_7z + [tar_filepath], not verbose) fileutils.remove(tar_filepath) else: flags = "-x" if verbose: flags = "-xv" run_cmd("tar", [flags, "-f", filepath, "-C", dest]) elif filepath.endswith(".zip"): if os_name() == "win": run_cmd("7z", args_7z + [filepath], not verbose) else: flags = "" if not verbose: flags = "-qq" run_cmd("unzip", [flags, filepath, "-d", dest]) else: #for all other types (example .7z) try 7z run_cmd("7z", args_7z + [filepath], not verbose) except exceptions.CommandNotFoundError: #change message raise exceptions.CommandNotFoundError("Could not find a program for extracting file (unzip, tar, 7z)")
def uninstall(self, package_name): if not self.is_installed(package_name): raise exceptions.BundleError(package_name + " is not installed") files_delete = self.list_files(package_name) connection = sqlite3.connect(self._manifest_path) cursor = connection.cursor() query = "SELECT id FROM installed WHERE name = ?" lib_id = cursor.execute(query, (package_name,)).fetchone()[0] cursor.execute("DELETE FROM files WHERE id = ?", (lib_id,)) cursor.execute("DELETE FROM installed WHERE id = ?", (lib_id,)) cursor.execute("DELETE FROM dep_graph WHERE name = ?", (package_name,)) connection.commit() connection.close() for name in files_delete: if os.path.exists(os.path.join(self.path, name)): fileutils.remove(os.path.join(self.path, name)) else: logging.getLogger().warning("'{0}' does not exist".format(os.path.join(self.path, name)))
def test_rm_dir(self): fileutils.remove(["/tmp"]) output = self.out.getvalue().strip() self.assertRegexpMatches(output, "is a directory, can't remove it$")
def test_rm_unknown_file(self): fileutils.remove(["/unknown"]) output = self.out.getvalue().strip() self.assertRegexpMatches(output, "does not exist$")
def record(game, nextGame): filename = makePath( expandPath(AudioDirectory) , '.'.join([game['filename'], Encoder]) ) latest = makePath(expandPath(AudioDirectory), 'latest.ogg') # build the commands recorder = ' '.join([ 'arecord' # audio recorder , '-q' # quiet , '-d {duration}' # recording time , '--max-file-time {duration}' # recording time before switching files (must be >= recording time) , '-c 2' # input stream is 2 channels , '-f S16' # input stream is 16 bit signed , '-r 44100' # rate of input stream is 44.1kHz , '-D {device}' # audio generator , '-t raw' # output format is raw (don't use .wav, it cuts out after 3 hours and 22 minutes because of a size limit on .wav files) ]).format( duration = 3600*RecordingDuration, device = SharkAudioAddr ) if Encoder == 'ogg': encoder = ' '.join([ 'oggenc' # Ogg encoder , '-Q' # quiet , '-r' # input format is raw , '--resample 8000' # sample rate (8000 and 11025 are suitable choices for AM radio) , '--downmix' # convert from stereo to mono , '-q 0' # quality level (range is -1 to 10 with 10 being highest) , '--ignorelength' # Allow input stream to exceed 4GB , '-o "{filename}"' # output file name , '--title "{title} ({date})"' # title , '--album "{title}"' # album , '--artist "{artist}"' # artist , '--date "{date}"' # date , '-' # read from standard input ]).format( filename = filename , title = game['desc'] , artist = 'The 49ers' , date = game['date'] ) elif Encoder == 'mp3': # Still not happy with the lame options. The ones below provide a # reasonable filesize, but the recording sounds very tinny, removing the # results in a nice sounding recording, but the files are a factor of # two too large. encoder = ' '.join([ 'lame' , '--quiet' # quiet , '--resample 8' # resample to rate , '-V3' # ??? , '--vbr-new' # ??? , '-q0' # quality level , '-B16' # maximum bit rate , '--lowpass 15.4' # apply lowpass filter , '--athaa-sensitivity 1' # ??? , '--tt "{title}"' # title , '--ta "{artist}"' # artist , '-' # read from standard input , '{filename}' # write to filename ]).format( filename = filename , title = game['desc'] , artist = 'The 49ers' , date = game['date'] ) elif Encoder == 'spx': # This generates files that sound a little better than the ogg files but # are much larger (odd because it is based on ogg and it tailored for # the spoken word, perhaps it is because I cannot get the -vbr option to # work). I am using the wideband option because it sounded # better and took less space than the narrowband option. encoder = ' '.join([ 'speexenc' , '-w' # wideband #, '--16bit' # 16 bit raw input stream #, '--le' # little endian input stream #, '--stereo' # stereo input stream , '--title "{title}"' # title , '--author "{artist}"' # artist , '-' # read from standard input , '{filename}' # write to filename ]).format( filename = filename , title = game['desc'] , artist = 'The 49ers' , date = game['date'] ) else: raise AssertionError, "%s: Unknown encoder" % encoder pipeline = '{recorder} | {encoder}'.format( recorder=recorder, encoder=encoder ) # assure destination directory exists mkdir(expandPath(AudioDirectory)) # create a symbolic link to the latest game remove(latest) try: os.symlink(filename, latest) except (IOError, OSError), err: sys.exit("%s: %s." % (err.filename, err.strerror))
from abraxas.prefs import GPG_BINARY from fileutils import remove from textwrap import dedent import sys import os # Initialization (fold) fast, printSummary, printTests, printResults, colorize, parent, coverage = cmdLineOpts() if coverage is False: python = pythonCmd() else: python = coverageCmd(source=coverage) testsRun = 0 failures = 0 remove("./generated_settings") os.chmod("test_key", 0o700) class Case: CONTEXT = {} OUTPUT = [] NAMES = set() def __init__(self, name, stimulus, result=None, output=None, error=None, clean=False): self.stimulus = stimulus # python code to evaluate self.name = name # name of test case, arbitrary but should be unique assert name not in Case.NAMES Case.NAMES.add(name) self.expected_result = result # expected result from evaluating the stimulus self.expected_output = output.strip().split("\n") if output else []
def _install(self, formula_name, **kwargs): formula = formulamanager.get(formula_name, self._context) formula_options = {} force_install = False clean_src = False if kwargs.has_key("formula_options"): formula_options = kwargs["formula_options"] if kwargs.has_key("variant"): formula_options["variant"] = kwargs["variant"] if kwargs.has_key("force"): force_install = kwargs["force"] if kwargs.has_key("clean_src"): clean_src = kwargs["clean_src"] formula.set_options(formula_options) if not formula.is_kit and (force_install or not self._bundle.is_installed(formula.name)): if clean_src: build_src_dir = os.path.join(self._context.build_dir, "{0}-{1}".format(formula.name, formula.version)) if os.path.exists(build_src_dir): fileutils.remove(build_src_dir) src_dir = sourcemanager.get_source(config.global_config().build_dir(), formula.name, formula.version, formula.source) old_cwd = os.getcwd() os.chdir(src_dir) if formula.patches: path1 = os.path.join(formula.dir, "patches", formula.name) if formula.dir.endswith(config.os_name()): path2 = os.path.normpath(os.path.join(formula.dir, "..", "patches", formula.name)) else: path2 = os.path.join(formula.dir, config.os_name(), "patches", formula.name) patch_dirs = [path1, path2] sourcemanager.patch_source(formula.patches, patch_dirs, src_dir) #make sure we have clean install dir for each formula if os.path.exists(self._context.install_dir): fileutils.remove(self._context.install_dir) try: os.mkdir(self._context.install_dir) except OSError: #On Windows, it is sometimes necessary to wait a little after deleting a #directory before creating it again time.sleep(0.01) os.mkdir(self._context.install_dir) self._call_hook_functions(self.hooks.pre_build) logging.getLogger().info("Building {0}...".format(formula.name)) fileset = formula.build() self._call_hook_functions(self.hooks.post_build) logging.getLogger().info("Done") logging.getLogger().info("Installing {0}...".format(formula.name)) self._bundle.install(formula.name, formula.version, formula.depends_on.keys(), fileset, force_install) self._call_hook_functions(self.hooks.post_install) logging.getLogger().info("Done") os.chdir(old_cwd)
def capture(message): slack = Slacker(slackbot_settings.API_TOKEN) channel = message.channel._body['name'] filename = fileutils.capture() slack.files.upload(file_=filename, channels=channel) fileutils.remove(filename)