def set_mod(self, mod="dot"): """ Set the graphviz module to use @param self @param optional string mod name of the module. This can be a full path, file.ext or file. Default: 'dot' @throws TypeError if the passed argument is neither string nor dict @example depgraph.set_mod('/usr/bin/dot') # this will be bound to *nix systems @example depgraph.set_mod('dot') # this will find dot (*nix) or dot.exe (Win+OS/2) in the PATH """ if not is_str(mod): logger.error( _("%(func)s was called with wrong parameter type: required: [%(req)s], given: [%(got)s]"), {"func": "depgraph.set_mod", "req": "str", "got": ",".join(is_what(mod))}, ) raise TypeError binmod = mod if mod.find(os_sep) == -1: binmod = which(mod) # check for the binary in PATH environment if binmod == None: self.bin = "" self.mod = "" elif os_path.isfile(binmod) and os_access(binmod, os.X_OK): self.bin = binmod self.mod = mod else: self.bin = "" self.mod = ""
def set_mod(self, mod='dot'): """ Set the graphviz module to use @param self @param optional string mod name of the module. This can be a full path, file.ext or file. Default: 'dot' @throws TypeError if the passed argument is neither string nor dict @example depgraph.set_mod('/usr/bin/dot') # this will be bound to *nix systems @example depgraph.set_mod('dot') # this will find dot (*nix) or dot.exe (Win+OS/2) in the PATH """ if not is_str(mod): logger.error( _('%(func)s was called with wrong parameter type: required: [%(req)s], given: [%(got)s]' ), { 'func': 'depgraph.set_mod', 'req': 'str', 'got': ','.join(is_what(mod)) }) raise TypeError binmod = mod if mod.find(os_sep) == -1: binmod = which(mod) # check for the binary in PATH environment if binmod == None: self.bin = '' self.mod = '' elif os_path.isfile(binmod) and os_access(binmod, os.X_OK): self.bin = binmod self.mod = mod else: self.bin = '' self.mod = ''
def _open(self): for k, dsn in self._hub.items(): v = self._kwargs(dsn) if not v[0]: continue try: driver = __import__(v[0]) except ImportError as e: warnings.warn(repr(e)) else: try: if 'sqlite3' == v[0]: connect = driver.connect(dsn[11:]) #substr sqlite3:/// elif 'postgresql' == v[0]: connect = driver.open(dsn.replace('postgresql', 'pq')) #py-postgresql open elif 'psycopg2' == v[0]: connect = driver.connect(' '.join([ '='.join(l) for l in v[1].items()])) else: connect = driver.connect(v[1]) except driver.OperationalError as e: warnings.warn(repr(e)) else: if self._callback: self._callback(connect) self._hub[k] = connect if self._prepare: file_ = self._prepare.get(k, None) if file_: if os_path_exists(file_) and os_access(file_, os_R_OK): try: f = open(file_, 'r') except IOError as e: warnings.warn(repr(e)) else: sqls = f.read().split(';') try: cursor = connect.cursor() except driver.Error as e: warnings.warn(repr(e)) else: for sql in sqls: try: connect.execute(sql) except driver.Error as e: warnings.warn(repr(e)) finally: cursor.close() finally: f.close()
def touch_file(file_path): ''' Function will create a file, based on the path supplied, without actually writing anything to the file. We are performing an equivalent of Unix (touch). ''' def write(file_path): ''' Function essentially opens a file in 'w' mode, and writes nothing but a null string to the file. ''' with open(file_path, 'w') as f: f.write('') f.close() from sys import exc_info as sys_excinfo ## If the file foes not exist, we will attempt to create it ## and if we encounter a failure, we will raise an IOError if not os_path.exists(file_path): try: write(file_path) except IOError as e: print '%s %s\n%s' % (sys_excinfo()[1],\ '','Unable to create file!') return False else: return True ## If the file does exist, we need to make that we can ## write to the file try: if not os_access(file_path,os_canwrite): raise IOError(13,'Permission denied',file_path) else: write(file_path) return True except IOError as e: print '%s %s\n%s' % (sys_excinfo()[1],\ '','Unable to modify file!') return False
def touch_file(file_path): ''' Function will create a file, based on the path supplied, without actually writing anything to the file. We are performing an equivalent of Unix (touch). ''' def write(file_path): ''' Function essentially opens a file in 'w' mode, and writes nothing but a null string to the file. ''' with open(file_path, 'w') as f: f.write('') f.close() from sys import exc_info as sys_excinfo ## If the file foes not exist, we will attempt to create it ## and if we encounter a failure, we will raise an IOError if not os_path.exists(file_path): try: write(file_path) except IOError as e: print '%s %s\n%s' % (sys_excinfo()[1],\ '','Unable to create file!') return False else: return True ## If the file does exist, we need to make that we can ## write to the file try: if not os_access(file_path, os_canwrite): raise IOError(13, 'Permission denied', file_path) else: write(file_path) return True except IOError as e: print '%s %s\n%s' % (sys_excinfo()[1],\ '','Unable to modify file!') return False
def set(self, key, value): if key == "token_files_path": if not isdir(value): raise FileNotFoundError elif not os_access(value, W_OK): raise PermissionError if value and value[-1] != "/": value += "/" if type(value) is self.DATA_TYPES[key]: self.data[key] = value elif type(value) is dict: for i in value: if type(value[i]) is self.DATA_TYPES[key][i]: self.data[key] = value else: raise TypeError( f"Invalid type: \"{type(value[i]).__name__}\" provided, " f"\"{self.DATA_TYPES[key][i].__name__}\" required") else: raise TypeError( f"Invalid type: \"{type(value).__name__}\" provided, " f"\"{self.DATA_TYPES[key].__name__}\" required")
def existfile(filename): if os_path_exists(filename) and os_path_isfile(filename) and os_access(filename, os_W_OK): return True; #endif return False;
def exist(path): if os_path_exists(path) and os_path_isdir(path) and os_access(path, os_W_OK): return True; #endif return False;