# Prints updated README.md. It substitutes tables of commands
# with newly generated ones.

import sys
import re

import util
import const

import generate_table_of_functions

TARGET_LINE = "There are currently "
TABLES_TARGET_LINE_START = "Below is a list of most useful commands."
TABLES_TARGET_LINE_END = "How To Rename Commands"

readmeContent = util.getFileContents(const.README_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
veryInterestingFunctionsContent = util.getFileContents(
    const.VERY_INTERESTING_FUNCTIONS_FILENAME)


# Gets all function names that call the long function.
# Arguments:
#   * explanation - name of the long function in form of a sentence.
def getShortcuts(explanation):
    matches = [line for line in projectsRcContent if explanation in line]
    return matches[0].split(':')[0].strip()


# Generates tables of functions.
def getFunctionTables():
#
# Usage: remove-conflicts-from-rc.py
#
# Prints modified projects configuration file, so it is ready to
# be copied into users home directory as users config file.  It
# changes its header and comments out the commands that are
# already defined as aliases (in .bashrc, .profile, ...).

import sys
import re
import commands

import util
import const

projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
usersHeader = util.getFileContents(const.USERS_RC_HEADER)

def main():
  conflicts = set(commands.getstatusoutput('./get-conflicting-names')[1].split('\n'))
  header = True
  for line in projectsRcContent:
    line = line.strip()
    if line == "# LESS #":
      header = False
      print(''.join(usersHeader))
      print('')
    if header:
      continue
    lineIsAComment = line.startswith('#')
    if lineIsAComment:
Esempio n. 3
0
#!/usr/bin/python
#
# Usage: generate-table-of-functions.py
# Prints tables of all functions in md format.

import sys
import re

import util
import const

LENGTH_OF_CODE_SNIPPET = 15

aliasesContent = util.getFileContents(const.AL_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
interestingContent = util.getFileContents(const.LIST_OF_IMPORTANT_FUNCTIONS)


# Gets dictionary of options from standard_rc, so they can be
# substituted.
# Returns:
#   * dictionary of: "${_<COMMAND-NAME>_OPTIONS[@]}" -> options.
def getOptions():
    commandsWithOptions = {}
    for line in projectsRcContent:
        if ";" in line:
            tokens = line.split(";")
            command = "\"${_" + tokens[0].strip().upper() + "_OPTIONS[@]}\""
            options = tokens[1].strip()
            commandsWithOptions[command] = options
    return commandsWithOptions
#
# Usage: remove-conflicts-from-rc.py
#
# Prints modified projects configuration file, so it is ready to
# be copied into users home directory as users config file.  It
# changes its header and comments out the commands that are
# already defined as aliases (in .bashrc, .profile, ...).

import sys
import re
import commands

import util
import const

projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
usersHeader = util.getFileContents(const.USERS_RC_HEADER)


def main():
    conflicts = set(
        commands.getstatusoutput('./get-conflicting-names')[1].split('\n'))
    header = True
    for line in projectsRcContent:
        line = line.strip()
        if line == "# LESS #":
            header = False
            print(''.join(usersHeader))
            print('')
        if header:
            continue
Esempio n. 5
0
# Prints updated README.md. It substitutes tables of commands
# with newly generated ones.

import sys
import re

import util
import const

import generate_table_of_functions

TARGET_LINE = "There are currently [0-9]* commands"
TABLES_TARGET_LINE_START = "Below is a list of most useful commands."
TABLES_TARGET_LINE_END = "How To Rename Commands"

readmeContent = util.getFileContents(const.README_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
veryInterestingFunctionsContent = util.getFileContents(const.VERY_INTERESTING_FUNCTIONS_FILENAME)

# Gets all function names that call the long function.
# Arguments:
#   * explanation - name of the long function in form of a sentence.
def getShortcuts(explanation):
  matches = [line for line in projectsRcContent if explanation in line]
  return matches[0].split(':')[0].strip()

# Generates tables of functions.
def getFunctionTables():
  ta = ""
  # map of: "${_COMMAND_OPTIONS[@]}" -> options
  commandsWithOptions = generate_table_of_functions.getOptions()
Esempio n. 6
0
    return dict([(m[0], m[1]) for m in re.findall(r'(\w+):(\S+)', raw)])


def hasRequiredFields(passportMap):
    return reduce(lambda a, b: a and b,
                  [f in passportMap for f in requiredFields])


def isPassportValid(passportMap):
    if not hasRequiredFields(passportMap):
        return False

    return reduce(
        lambda a, b: a and b,
        [requiredFields[key](passportMap[key]) for key in requiredFields])


input = getFileContents('input.txt')
passports = input.split('\n\n')

print(
    len(
        list(
            filter(lambda a: hasRequiredFields(a),
                   [buildPassportMap(p) for p in passports]))))
print(
    len(
        list(
            filter(lambda a: isPassportValid(a),
                   [buildPassportMap(p) for p in passports]))))
Esempio n. 7
0
# If so it defines same completion for the function with shorter
# name. If the function doesn't have a completion defined, then
# it checks the completion of the function inside that function
# that gets called with "$@" (all command arguments).
#
# If the short name is already taken, then it's defined as an
# alias instead of a function.

import sys
import re

import util
import const

# Lists of lines of different files.
aliasesContent = util.getFileContents(const.AL_FILENAME)
usersRcContent = util.getFileContents(const.USERS_RC_FILENAME)
aliasesHeader = util.getFileContents(const.ALIASES_HEADER)


# Converts list of completion definitions into a dictionary that
# maps a command to its completion.
# Arguments:
#   * completions - list of completions ("complete -F _longopt
#       cat", ...) of all commands.
# Returns:
#   * Dictionary of: command -> completion ("cat" -> "complete
#       -F _longopt", ...) of all available commands.
def generateMapOfCompletions(completions):
    completionsMap = {}
    if not completions:
Esempio n. 8
0
import sys
import os
import re
import collections

import util
import const

# Messages that are printed in front of commented out
# definitions.
DELETED_OR_RENAMED_SIGNIFIER = "# DELETED OR RENAMED FUNCTION!: "
NEW_SIGNIFIER = "# NEW FUNCTION!: "

# Lists of lines of different files.
functionsContent = util.getFileContents(const.AL_FILENAME)
usersRcContent = util.getFileContents(const.USERS_RC_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
optionsComment = util.getFileContents(const.RC_OPTIONS_COMMENT)
usersHeader = util.getFileContents(const.USERS_RC_HEADER)
projectsHeader = util.getFileContents(const.PROJECTS_RC_HEADER)

# Returns list of all functions defined in standard_aliases,
# with names that start with two underscores (__). Names of the
# functions are converted from camelCase to sentence form.
# Returns:
#   * List of functions defined in standard_aliases.
def getFunctions():
  functionDescriptions = []
  # Goes trough aliases.
  for line in functionsContent:
#!/usr/bin/python
#
# Usage: generate-table-of-functions.py
# Prints tables of all functions in md format.

import sys
import re

import util
import const

LENGTH_OF_CODE_SNIPPET = 15

aliasesContent = util.getFileContents(const.AL_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
interestingContent = util.getFileContents(const.LIST_OF_IMPORTANT_FUNCTIONS)

# Gets dictionary of options from standard_rc, so they can be
# substituted.
# Returns:
#   * dictionary of: "${_<COMMAND-NAME>_OPTIONS[@]}" -> options.
def getOptions():
    commandsWithOptions = {}
    for line in projectsRcContent:
        if ";" in line:
            tokens = line.split(";")
            command = '"${_' + tokens[0].strip().upper() + '_OPTIONS[@]}"'
            options = tokens[1].strip()
            commandsWithOptions[command] = options
    return commandsWithOptions
Esempio n. 10
0
# If so it defines same completion for the function with shorter
# name. If the function doesn't have a completion defined, then
# it checks the completion of the function inside that function
# that gets called with "$@" (all command arguments).
#
# If the short name is already taken, then it's defined as an
# alias instead of a function.

import sys 
import re

import util
import const

# Lists of lines of different files.
aliasesContent = util.getFileContents(const.AL_FILENAME)
usersRcContent = util.getFileContents(const.USERS_RC_FILENAME)
aliasesHeader = util.getFileContents(const.ALIASES_HEADER)

# Converts list of completion definitions into a dictionary that
# maps a command to its completion.
# Arguments:
#   * completions - list of completions ("complete -F _longopt
#       cat", ...) of all commands.
# Returns: 
#   * Dictionary of: command -> completion ("cat" -> "complete
#       -F _longopt", ...) of all available commands.
def generateMapOfCompletions(completions):
  completionsMap = {}
  if not completions:
    return completionsMap
Esempio n. 11
0
import sys
import os
import re
import collections

import util
import const

# Messages that are printed in front of commented out
# definitions.
DELETED_OR_RENAMED_SIGNIFIER = "# DELETED OR RENAMED FUNCTION!: "
NEW_SIGNIFIER = "# NEW FUNCTION!: "

# Lists of lines of different files.
functionsContent = util.getFileContents(const.AL_FILENAME)
usersRcContent = util.getFileContents(const.USERS_RC_FILENAME)
projectsRcContent = util.getFileContents(const.PROJECTS_RC_FILENAME)
optionsComment = util.getFileContents(const.RC_OPTIONS_COMMENT)
usersHeader = util.getFileContents(const.USERS_RC_HEADER)
projectsHeader = util.getFileContents(const.PROJECTS_RC_HEADER)


# Returns list of all functions defined in standard_aliases,
# with names that start with two underscores (__). Names of the
# functions are converted from camelCase to sentence form.
# Returns:
#   * List of functions defined in standard_aliases.
def getFunctions():
    functionDescriptions = []
    # Goes trough aliases.
Esempio n. 12
0
from util import getFileContents
from functools import reduce

def countUniqueChars(word):
    bucket = set(word)
    return len(bucket)

def countUnanimous(group):
    ledger = {}
    count = 0
    listOfPeople = group.split('\n')
    groupCount = len(listOfPeople)
    for person in listOfPeople:
        for yes in person:
            if yes in ledger:
                ledger[yes] += 1
            else:
                ledger[yes] = 1
            if ledger[yes] == groupCount:
                count += 1
    return count

input = getFileContents('input.txt').rstrip('\n')
groups = input.split('\n\n')

counts = [countUniqueChars(g.replace('\n','')) for g in groups]

print(reduce(lambda a,b: a+b,counts))
print(reduce(lambda a,b: a+b,[countUnanimous(g) for g in groups]))