Ejemplo n.º 1
0
def get_commit_errors(file_type, function):
  checkable = True
  if file_type == "js":
    checkable = config.getboolean("commit", "CHECK_JAVASCRIPT")
  elif file_type == "php":
    checkable = config.getboolean("commit", "CHECK_PHP")

  if not checkable:
    return None

  files = _get_commit_files(file_type)
  if not files:
    return None

  #Get files are both in cached zone and modified zone
  system("git diff --name-status > /tmp/git_hook")
  modified_files = _get_files(file_type, 2)
  if modified_files:
    #Ask user whether add a file in modified zone to commit
    modified_files = [modified_file for modified_file in modified_files if modified_file in files]
    stdin = open('/dev/tty')
    for modified_file in modified_files:
      print(
        'File %s has been modified but not in the cached zone, add it into ? [Y|n]' %
        colored(modified_file, 'red')
      )
      if not stdin.readline().strip().lower().startswith('n'):
        system('git add %s' % modified_file)

    stdin.close()

  errors = []
  for file_path in files:
    if path.exists(file_path):
      file_error = function(file_path)
      if file_error:
        errors.append(file_error)

  if errors:
    errors = colored(
      "There are some errors in below %s files:\n\n" % file_type, "magenta"
    ) + "\n".join(errors).strip("\n")

  return errors
Ejemplo n.º 2
0
def become_daemon():
    try:
        pid = fork()
    except OSError:
        print 'unable to fork'
        exit(1)

    if pid == 0:
        # Daemonize
        setsid()
        # We redirect only the 3 first descriptors
        file_desc = os_open(devnull, O_RDWR)
        stdin.close()
        dup2(file_desc, 0)
        stdout.flush()
        dup2(file_desc, 1)
        stderr.flush()
        dup2(file_desc, 2)
    else:
        exit()
Ejemplo n.º 3
0
stdin = open('A-large-practice.in', 'r')
#stdout = open('A-small.out', 'w')
stdout = open('A-large.out', 'w')

T = int(stdin.readline().strip())

for t in range(0, T):

    (A, N) = [int(x) for x in stdin.readline().strip().split()]

    m = [int(x) for x in stdin.readline().strip().split()]

    ans = N

    op = 0

    m.sort()

    while A > 1 and len(m) > 0:
        while A <= m[0]:
            A += A - 1
            op += 1
        A += m[0]
        m[0:1] = []
        ans = min(ans, op + len(m))

    stdout.write('Case #{0}: {1}\n'.format(t+1, ans))

stdin.close()
stdout.close()