def setup(maxjobs): global _fds, _toplevel if _fds: return # already set up _debug('setup(%d)\n' % maxjobs) flags = ' ' + os.getenv('MAKEFLAGS', '') + ' ' FIND = ' --jobserver-fds=' ofs = flags.find(FIND) if ofs >= 0: s = flags[ofs+len(FIND):] (arg,junk) = s.split(' ', 1) (a,b) = arg.split(',', 1) a = atoi.atoi(a) b = atoi.atoi(b) if a <= 0 or b <= 0: raise ValueError('invalid --jobserver-fds: %r' % arg) try: fcntl.fcntl(a, fcntl.F_GETFL) fcntl.fcntl(b, fcntl.F_GETFL) except IOError, e: if e.errno == errno.EBADF: raise ValueError('broken --jobserver-fds from make; prefix your Makefile rule with a "+"') else: raise _fds = (a,b)
def validRange(string): #print 'valid', string if atoi(string) >= 0 and atoi(string) <= 255 and \ (len(string) == 2 and string[0] != '0') or \ (len(string) == 3 and string[0] != '0' and string[1] != '0') or \ len(string) == 1: return True else: return False
import os from atoi import atoi if not os.environ.get('REDO'): import sys sys.stderr.write('%s: error: must be run from inside a .do\n' % sys.argv[0]) sys.exit(100) PWD = os.environ.get('REDO_PWD', '') TARGET = os.environ.get('REDO_TARGET', '') DEPTH = os.environ.get('REDO_DEPTH', '') DEBUG = atoi(os.environ.get('REDO_DEBUG', '')) DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0 DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0 KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0 LOG = atoi(os.environ.get('REDO_LOG', '1')) # defaults on LOG_INODE = os.environ.get('REDO_LOG_INODE', '') COLOR = atoi(os.environ.get('REDO_COLOR', '1')) # defaults on # subprocesses mustn't pretty-print if a parent is running redo-log PRETTY = (not LOG) and atoi(os.environ.get('REDO_PRETTY', '1')) SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 STARTDIR = os.environ.get('REDO_STARTDIR', '') RUNID = atoi(os.environ.get('REDO_RUNID')) or None BASE = os.environ['REDO_BASE'] while BASE and BASE.endswith('/'): BASE = BASE[:-1] UNLOCKED = os.environ.get('REDO_UNLOCKED', '') and 1 or 0
# only do this from the toplevel redo process, so unless the user # deliberately starts more than one redo on the same repository, it's # sort of ok. mkdirp('%s/.redo' % base) for f in glob.glob('%s/.redo/lock*' % base): os.unlink(f) if not vars.DEPTH: # toplevel call to redo exenames = [os.path.abspath(sys.argv[0]), os.path.realpath(sys.argv[0])] if exenames[0] == exenames[1]: exenames = [exenames[0]] dirnames = [os.path.dirname(p) for p in exenames] os.environ['PATH'] = ':'.join(dirnames) + ':' + os.environ['PATH'] try: j = atoi.atoi(opt.jobs or 1) if j < 1 or j > 1000: err('invalid --jobs value: %r\n' % opt.jobs) jwack.setup(j) try: retcode = builder.main(targets, builder.build) finally: jwack.force_return_tokens() if retcode: err('exiting: %d\n' % retcode) sys.exit(retcode) except KeyboardInterrupt: sys.exit(200)
import os from atoi import atoi if not os.environ.get('REDO'): import sys sys.stderr.write('%s: error: must be run from inside a .do\n' % sys.argv[0]) sys.exit(100) PWD = os.environ.get('REDO_PWD', '') TARGET = os.environ.get('REDO_TARGET', '') TARGET_ONLY = os.environ.get('REDO_TARGET_ONLY', '') and 1 or 0 DEPTH = os.environ.get('REDO_DEPTH', '') DEBUG = atoi(os.environ.get('REDO_DEBUG', '')) DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0 DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0 OLD_ARGS = os.environ.get('REDO_OLD_ARGS', '') and 1 or 0 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0 KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 STARTDIR = os.environ.get('REDO_STARTDIR', '') RUNID = atoi(os.environ.get('REDO_RUNID')) or None BASE = os.environ['REDO_BASE'] while BASE and BASE.endswith('/'): BASE = BASE[:-1] UNLOCKED = os.environ.get('REDO_UNLOCKED', '') and 1 or 0 os.environ['REDO_UNLOCKED'] = '' # not inheritable by subprocesses NO_OOB = os.environ.get('REDO_NO_OOB', '') and 1 or 0
#!/usr/bin/env python """ the sys.path.append in the next section is needed since we didn't 'properly' install the module to /usr/share/python. If we had done this this would not have been neccessary. """ import sys sys.path.append('build/lib.linux-i686-2.7') # noinspection PyPep8 import atoi print(atoi.atoi('-7.6'))
import os from atoi import atoi if not os.environ.get('REDO'): import sys sys.stderr.write('%s: error: must be run from inside a .do\n' % sys.argv[0]) sys.exit(100) PWD = os.environ.get('REDO_PWD', '') TARGET = os.environ.get('REDO_TARGET', '') DEPTH = os.environ.get('REDO_DEPTH', '') DEBUG = atoi(os.environ.get('REDO_DEBUG', '')) DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0 DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0 OLD_ARGS = os.environ.get('REDO_OLD_ARGS', '') and 1 or 0 VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 XTRACE = os.environ.get('REDO_XTRACE', '') and 1 or 0 KEEP_GOING = os.environ.get('REDO_KEEP_GOING', '') and 1 or 0 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 STARTDIR = os.environ.get('REDO_STARTDIR', '') RUNID = atoi(os.environ.get('REDO_RUNID')) or None BASE = os.environ['REDO_BASE'] while BASE and BASE.endswith('/'): BASE = BASE[:-1] UNLOCKED = os.environ.get('REDO_UNLOCKED', '') and 1 or 0 os.environ['REDO_UNLOCKED'] = '' # not inheritable by subprocesses NO_OOB = os.environ.get('REDO_NO_OOB', '') and 1 or 0 os.environ['REDO_NO_OOB'] = '' # not inheritable by subprocesses
import os import atoi TARGET = os.environ.get('REDO_TARGET', '') DEPTH = os.environ.get('REDO_DEPTH', '') DEBUG = atoi.atoi(os.environ.get('REDO_DEBUG', '')) VERBOSE = os.environ.get('REDO_VERBOSE', '') and 1 or 0 SHUFFLE = os.environ.get('REDO_SHUFFLE', '') and 1 or 0 STARTDIR = os.environ.get('REDO_STARTDIR', '') BASE = os.environ.get('REDO_BASE', '') if BASE: BASE = os.path.abspath(BASE) while BASE and BASE.endswith('/'): BASE = BASE[:-1]
def catlog(t): global total_lines, status if t in already: return if t != '-': depth.append(t) _fix_depth() already.add(t) mydir = os.path.dirname(t) if t == '-': f = sys.stdin fid = None loglock = None logname = None else: try: sf = state.File(name=t, allow_add=False) except KeyError: sys.stderr.write('redo-log: [%s] %r: not known to redo.\n' % ( os.getcwd(), t, )) sys.exit(24) fid = sf.id del sf state.rollback() logname = state.logname(fid) loglock = state.Lock(fid + state.LOG_LOCK_MAGIC) loglock.waitlock(shared=True) f = None delay = 0.01 was_locked = is_locked(fid) line_head = '' width = _tty_width() while 1: if not f: try: f = open(logname) except IOError, e: if e.errno == errno.ENOENT: # ignore files without logs pass else: raise if f: # Note: normally includes trailing \n. # In 'follow' mode, might get a line with no trailing \n # (eg. when ./configure is halfway through a test), which we # deal with below. line = f.readline() else: line = None if not line and (not opt.follow or not was_locked): # file not locked, and no new lines: done break if not line: was_locked = is_locked(fid) if opt.follow: # Don't display status line for extremely short-lived runs if opt.status and time.time() - start_time > 1.0: width = _tty_width() head = 'redo %s ' % ('{:,}'.format(total_lines)) tail = '' for n in reversed(depth): remain = width - len(head) - len(tail) # always leave room for a final '... ' prefix if remain < len(n) + 4 + 1 or remain <= 4: if len(n) < 6 or remain < 6 + 1 + 4: tail = '... %s' % tail else: start = len(n) - (remain - 3 - 1) tail = '...%s %s' % (n[start:], tail) break elif n != '-': tail = n + ' ' + tail status = head + tail if len(status) > width: sys.stderr.write('\nOVERSIZE STATUS (%d):\n%r\n' % (len(status), status)) assert (len(status) <= width) sys.stdout.flush() sys.stderr.write('\r%-*.*s\r' % (width, width, status)) time.sleep(min(delay, 1.0)) delay += 0.01 continue total_lines += 1 delay = 0.01 if not line.endswith('\n'): line_head += line continue if line_head: line = line_head + line line_head = '' if status: sys.stdout.flush() sys.stderr.write('\r%-*.*s\r' % (width, width, '')) status = None g = re.match(REDO_LINE_RE, line) if g: # FIXME: print prefix if @@REDO is not at start of line. # logs.PrettyLog does it, but only if we actually call .write(). words, text = g.groups() kind, pid, when = words.split(':')[0:3] pid = atoi(pid) relname = _rel(topdir, mydir, text) fixname = os.path.normpath(os.path.join(mydir, text)) if kind == 'unchanged': if opt.unchanged: if opt.debug_locks: logs.meta(kind, relname, pid=pid) elif fixname not in already: logs.meta('do', relname, pid=pid) if opt.recursive: if loglock: loglock.unlock() catlog(os.path.join(mydir, text)) if loglock: loglock.waitlock(shared=True) already.add(fixname) elif kind in ('do', 'waiting', 'locked', 'unlocked'): if opt.debug_locks: logs.meta(kind, relname, pid=pid) logs.write(line.rstrip()) elif fixname not in already: logs.meta('do', relname, pid=pid) if opt.recursive: assert text if loglock: loglock.unlock() catlog(os.path.join(mydir, text)) if loglock: loglock.waitlock(shared=True) already.add(fixname) elif kind == 'done': rv, name = text.split(' ', 1) logs.meta(kind, rv + ' ' + _rel(topdir, mydir, name)) else: logs.write(line.rstrip()) else: if opt.details: logs.write(line.rstrip())
# This is better to use than os.path.relpath, because your paths might include # symlinks that make a/b/../c not equal to a/c. PWD = os.environ.get('REDO_PWD', '') # The path to the target currently being built, relative to PWD. TARGET = os.environ.get('REDO_TARGET', '') # The depth of redo recursion, in the form of a string of space characters. # The deeper we go, the more space characters we append. DEPTH = os.environ.get('REDO_DEPTH', '') # The value of the --overwrite flag. OVERWRITE = os.environ.get('REDO_OVERWRITE', '') and 1 or 0 # The value of the -d flag. DEBUG = atoi(os.environ.get('REDO_DEBUG', '')) # The value of the --debug-pids flag. DEBUG_PIDS = os.environ.get('REDO_DEBUG_PIDS', '') and 1 or 0 # The value of the --debug-locks flag. DEBUG_LOCKS = os.environ.get('REDO_DEBUG_LOCKS', '') and 1 or 0 # The value of the --old-args flag. OLD_ARGS = os.environ.get('REDO_OLD_ARGS', '') and 1 or 0 # The value of the --old-stdout flag. OLD_STDOUT = os.environ.get('REDO_OLD_STDOUT', '') and 1 or 0 # The value of the --warn-stdout flag. WARN_STDOUT = os.environ.get('REDO_WARN_STDOUT', '') and 1 or 0
import os from atoi import atoi if not os.environ.get("REDO"): import sys sys.stderr.write("%s: error: must be run from inside a .do\n" % sys.argv[0]) sys.exit(100) PWD = os.environ.get("REDO_PWD", "") TARGET = os.environ.get("REDO_TARGET", "") DEPTH = os.environ.get("REDO_DEPTH", "") DEBUG = atoi(os.environ.get("REDO_DEBUG", "")) DEBUG_LOCKS = os.environ.get("REDO_DEBUG_LOCKS", "") and 1 or 0 DEBUG_PIDS = os.environ.get("REDO_DEBUG_PIDS", "") and 1 or 0 OLD_ARGS = os.environ.get("REDO_OLD_ARGS", "") and 1 or 0 VERBOSE = os.environ.get("REDO_VERBOSE", "") and 1 or 0 XTRACE = os.environ.get("REDO_XTRACE", "") and 1 or 0 KEEP_GOING = os.environ.get("REDO_KEEP_GOING", "") and 1 or 0 SHUFFLE = os.environ.get("REDO_SHUFFLE", "") and 1 or 0 STARTDIR = os.environ.get("REDO_STARTDIR", "") RUNID = atoi(os.environ.get("REDO_RUNID")) or None BASE = os.environ["REDO_BASE"] while BASE and BASE.endswith("/"): BASE = BASE[:-1] UNLOCKED = os.environ.get("REDO_UNLOCKED", "") and 1 or 0 os.environ["REDO_UNLOCKED"] = "" # not inheritable by subprocesses NO_OOB = os.environ.get("REDO_NO_OOB", "") and 1 or 0 os.environ["REDO_NO_OOB"] = "" # not inheritable by subprocesses