def __init__(self, config): self.config = np.str(config) # # Read the config file # Comment line(s) start with '#' # Followed by some mandatory fields # nx # ny # dt # Ra # Pr # Sub-folder with the raw results # Sub-folder with the processed results # Sub-folder with the figures # [nx, ny, dt, ra, pr, raw, post, fig] = np.loadtxt(self.config, dtype=str) self.nx = np.int(nx) self.ny = np.int(ny) self.dt = np.float(dt) self.ra = np.float(ra) self.pr = np.float(pr) self.rawfolder = np.str(raw) self.postfolder = np.str(post) self.figfolder = np.str(fig) # Here, RK3 final time step is hard-coded self.dt = (4. / 12.) * self.dt # 3./4. - 5./12. # Here, the size of the domain in X is hard-coded self.xx = np.linspace(0., 1., nx) # Read the Y grid, the name of the file is hard-coded self.yy = np.loadtxt(ospjoin(self.rawfolder, "yp.dat"), dtype=float)[:, 1]
def _get_items(self, take_hidden=False): """ Method that populates self.children with directories contained in itself as a list of DirNodes and self.files with files contained in itself as a list of path strigs. @param skip_hidden: whether to skip hidden directories or not @type skip_hidden: boolean """ for item in os.listdir(self.path): if item.startswith(".") and not take_hidden: continue if os.path.isdir(ospjoin(self.path, item)): child_path = ospjoin(self.path, item) self.children.append(_DirNode(child_path, self)) else: self.files.append(item)
def tmp_cleanup(disabled, print_warning): if disabled: return tmp = [x for x in listdir("/tmp") if re.match(r"^colorlist_.*", x)] if len(tmp) > 5: warn(print_warning, "Performing cleanup in '/tmp'...") try: for file in tmp: path = ospjoin("/tmp", file) remove(path) except OSError as err: warn(print_warning, f"Could not perform cleanup: {err.strerror}") return
def list_from_file(self, path): """ Method that populates self.items with directories listed with their destination directories (see documentation for more details) in a file. @param path: path of the file listing directories @type path: string @raise IOError: when file doesn't exist """ list_file = open(path, "r") for line in list_file: path, dest = line.split(" -> ", 2) if os.path.abspath(path): self.items.append((_DirNode(path), dest)) else: full_path = ospjoin(os.path.getcwd(), path) self.items.append(_DirNode(full_path, dest))
def _find_matching_item(name_part, dest): """ Function that finds directory in dest directory whose name matches the first argument. @param name_part: part of the name to be matched @type name_part: string @param dest: destination directory where to look for @type dest: string @return: full path of the matching directory (if any) @raise NoMatchError: if destination directory doesn't contain any matching directory """ try: for item in os.listdir(dest): if re.match(name_part + ".*", item, re.IGNORECASE): return ospjoin(dest, item) raise NoMatchError("No matching directory found.") except IOError as ioerr: raise NoMatchError(str(ioerr))
from os.path import abspath, dirname, join as ospjoin import re here = abspath(dirname(__file__)) def find_version(filename): with open(filename, "r") as f: version_file = f.read() version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") project_version = find_version(ospjoin(here, "fastnml", "__init__.py")) # Get the long description from the README file with open(ospjoin(here, "README.md"), encoding="utf-8") as f: long_description = f.read() setup( name="fastnml", version=project_version, description="A simple fast namelist parser", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/jacobwilliams/fastnml", author="Jacob Williams", author_email="*****@*****.**", classifiers=[
def archive_subtree(self, dest, compression="gzip", verbose=False): """ Method that archives subtree. It makes tarballs from directories containing only files or it makes same-named directories in the destination directory for directories containing subdirectories and it makes tarballs from files contained in these directories. @param dest: destination directory where to make subtree @type dest: string @param compression: compression algorithm to be used (possible values are "gzip", "bzip", "xz", "none") @type compression: string @param verbose: whether to pipe tar's output to stdin or not @type verbose: boolean @raise ArchivingProblemError: in case there was some problem while archiving (i.e. tar's return code was not 0) """ print("Archiving files in {0}...".format(self.path), end="") sys.stdout.flush() retcode = 0 args = [] if verbose: args.append("-v") if compression != "none": args.append(COMPRESSION_TYPE[compression]) if not self.children: args.extend( [ "-c", # don't want absolute paths "-C", os.path.dirname(self.path.rstrip("/")), "-f", ospjoin(dest, self.name + ".tar" + COMPRESSION_EXT[compression]), # option -C changes directory, so we can use names self.name, ] ) _call_tar(args, verbose) else: if not os.path.exists(ospjoin(dest, self.name)): try: os.mkdir(ospjoin(dest, self.name)) except OSError as oserr: raise ArchivingProblemError( "Cannot create directory {0}.\n{1}".format(ospjoin(dest, self.name), oserr) ) if self.files: args.extend( [ "-c", "-C", self.path, "-f", ospjoin(dest, self.name, self.name + ".tar" + COMPRESSION_EXT[compression]), ] ) args.extend(self.files) _call_tar(args, verbose) print("done") if retcode != 0: raise ArchivingProblemError("Return code of tar (archiving {0}) was: {1}".format(self.path, retcode)) for child in self.children: child.archive_subtree(ospjoin(dest, self.name), compression, verbose)
sparkfun_openscale.py Author: Danyal Ahsanullah Date: 6/29/2018 Copyright (c): 2018 Danyal Ahsanullah License: N/A Description: library for interfacing the Sparkfun OpenScale. """ import os import yaml import serial from os.path import join as ospjoin from typing import Tuple, Dict, Union from libs.hal.constants import LOCK CFG_FILE_PATH = ospjoin(os.environ.get('OPENSCALE_CFG_PATH', '../../CONFIGS/'), 'openscale_cfg.yml') class OpenScale(serial.Serial): BAUDRATES = (1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000) # prompt for initial opening of config menu: # # Serial Load Cell Converter version 1.0 # By SparkFun Electronics # No remote sensor found # System Configuration # 1) Tare scale to zero [8647409] # 2) Calibrate scale [262] # 3) Timestamp [On] # 4) Set report rate [953]