def main(source, dest): """Rename a Git repository and update its remote accordingly.""" basicConfig(level=DEBUG) try: repo = Repo(source) except OSError as error: logger.exception('Error:') exit(1) else: dest = Path(dest) try: dest = dest.with_suffix('.git') except ValueError: logger.exception('Error:') exit(1) logger.info('Using dest: %s', dest) remote = repo.remote() logger.debug('Old URL: %s', remote.url) origin = Path(remote.url) logger.debug('Parent: %s', origin.parent) new = origin.parent / dest logger.info('Using URL: %s', new) conf = remote.config_writer conf.set('url', str(new)) conf.release() Path(source).rename(dest) exit(0)
def __init__(self, name: str): pipe = win32file.CreateFile( '\\\\.\\pipe\\' + name, win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None, win32file.OPEN_EXISTING, 0, None) if win32pipe.SetNamedPipeHandleState(pipe, win32pipe.PIPE_READMODE_MESSAGE, None, None): raise RuntimeError('Could not set pipe mode to PIPE_TYPE_MESSAGE') root.info('WINAPI: Connected to named pipe %s: %s' % (name, str(pipe))) super(NamedPipeClient, self).__init__(pipe)
def __init__(self, name: str, wait_connected: bool = False, block_io: bool = True): pipe = win32pipe.CreateNamedPipe( '\\\\.\\pipe\\' + name, win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | (win32pipe.PIPE_WAIT if block_io else win32pipe.PIPE_NOWAIT), 1, 65536, 65536, 0, None) root.info('WINAPI: Created named pipe %s: %s' % (name, str(pipe))) if wait_connected: win32pipe.ConnectNamedPipe(pipe, None) super(NamedPipeServer, self).__init__(pipe)
def register(func, name=None): # this never runs as the statements lowering the debug level to info have not run yet when this runs root.info("I'm logging in register and my name is: " + __name__) # the following does run print( "I'm printing in register. This is run when the function mean is defined, not when it's called" ) print( "This is run when the function mean is defined; not when it's called") print("As such, this is run when the module or the function is imported") # note that the function is registered under its name in the dictionary SUMMARIES[name or func.__name__] = func return func
def render_image(library, cid): cache_key = h('%s/%s/png' % (library, cid)) if cache.get(cache_key) is not None: return cache.get(cache_key) # load the sdf to determine the url if library == 'manual-sdf': sdf = cid else: lib = get_library_by_name(library) sdf = SDFFile.objects.get(compound__library=lib, compound__cid__iexact=cid).sdffile # may throw SDFFile.DoesNotExist sdflines = [] ptn = re.compile(r'^M\s+END') for i in sdf.encode('utf-8').splitlines(): sdflines.append(i) if ptn.match(i): break sdf = '\n'.join(sdflines) url = structure_renderer_url + md5(sdf).hexdigest() root.info('trying to load from cache the structure of %s:%s' % (library, cid)) # see whether renderer has the image in cache try: renderer = urlopen(url) assert renderer.getcode() != 404 renderer.close() except: # not ready. so post the sdf to the renderer renderer = urlopen(structure_renderer_url, urlencode(dict(sdf=sdf))) url = renderer.geturl() renderer.close() cache.set(cache_key, url, 3600 * 24) return url
def mean(x): root.info("I'm in the logger for mean, and my name is: " + __name__) print("I'm printing in mean") return arith_mean(x)
def wrapped(*args, **kwargs): root.info( "{} was called: {} {}".format( func.__name__, args, kwargs)) # Encapsulate the original return func(*args, **kwargs)