示例#1
0
def start_module():
    os.system('cls' if os.name == 'nt' else 'clear')
    file_name = "postion.csv"
    table = data_manager.import_file(file_name)

    menu = ["Create position",
            "Read position",
            "Read positions",
            "Update position",
            "Delete position",
            "Back to main menu"]

    ui.print_menu(menu)
    x = int(ui.get_input("Enter a number: "))

    if x == 1:
        create_position(file_name)
    elif x == 2:
        position_id = ui.get_input("Enter a position ID here: ")
        read_position(table, position_id)
    elif x== 3:
        read_positions(table)
    elif x == 4:
        position_id = ui.get_input("Enter a position ID here: ")
        update_position(table, file_name, position_id)
    elif x == 5:
        delete_position(table, file_name)
    elif x == 6:
        main.main()
示例#2
0
def start_module():  # Prints menu
    os.system('cls' if os.name == 'nt' else 'clear')
    file_name = "student.csv"
    table = data_manager.import_file(file_name)
    menu = [
        "Create student", "Read student", "Read students", "Update students",
        "Activate / Deactivate a student", "Delete student", "Back to main"
    ]

    ui.print_menu(menu)
    x = int(ui.get_input("Enter a number here: "))
    if x == 1:
        create_student(file_name)
    if x == 2:
        student_ID = ui.get_input("Enter a student ID here: ")
        read_student(student_ID, table)
    if x == 3:
        read_students(table)
    if x == 4:
        student_ID = ui.get_input("Enter a student ID here: ")
        update_student(table, student_ID, file_name)
    if x == 5:
        student_ID = ui.get_input("Enter a student ID here: ")
        activate_deactivate_student(table, student_ID, file_name)
    if x == 6:
        student_ID = ui.get_input("Enter a student ID here: ")
        delete_student(table, student_ID, file_name)
    if x == 7:
        main.main()
示例#3
0
def create_student(file_name):  # Create Student

    student_ID = ui.generate_random()
    student_name = ui.get_input("Enter a student name here: ")
    student_age = ui.get_input("Enter a student age here: ")
    student_active = "Active"
    student = [student_ID, student_name, student_age, student_active]

    data_manager.export_file(student, file_name, "a")
示例#4
0
def update_student(table, student_ID, file_name):  # Update Student
    updated_name = ui.get_input("Enter updated name here: ")
    updated_age = ui.get_input("Enter updated age here: ")

    for i in table:
        if i[0] == student_ID:
            i[1] = updated_name
            i[2] = updated_age

    data_manager.export_file(table, file_name, "w")
示例#5
0
def update_company(table, file_name):
    '''

    Users can update the details of existing companies by first entering their ID and then the information (name) to be updated.
    IDs cannot be updated.
    Company names can be updated, but they should stay unique.'''
    company_id_by_user = ui.get_input("Enter company id: ")
    for i in table:
        if i[0] == company_id_by_user:
            new_name = ui.get_input("Enter new company name: ")
            i[1] = new_name
            new_datas = [i]

    data_manager.export_file(table, file_name, "w")
def start_searching_functions():
    title = "Searching menu"
    commands = [
        "Search for games by number of players", "Search by title",
        "Search by type", "Back to main menu"
    ]
    games_list_of_lists = file_handling.import_file(filename="games.csv")
    ui.print_menu(title, commands)
    chosen_option = ui.menu_handling(1, 4)

    while True:
        if chosen_option == 1:  # Wyszukuje gry dla określonej liczby graczy
            os.system("clear")
            number = ui.get_input("Search for games for how many peaople?",
                                  ["Enter number of playing people"])
            results = search_for_games_by_number_of_players(
                games_list_of_lists, number)
            ui.print_table(results)
            start_searching_functions()
        elif chosen_option == 2:  # Wyszukuje grę na podstawie tytułu
            os.system("clear")
            search_by_title(games_list_of_lists)
            start_searching_functions()
        elif chosen_option == 3:  # Wyszukuje grę danego typu
            os.system("clear")
            search_by_type(games_list_of_lists)
            start_searching_functions()
        elif chosen_option == 4:  # Powrót do głównego menu
            main_program.main()
示例#7
0
def create_position(file_name):
    '''

    Users can create new positions. A position has an ID, description, number of seats and a “Company ID”.
    Position IDs are unique amongst other positions.
    Descriptions cannot be empty.
    The number of seats must be greater than 0.
    Company ID must exist.'''

    position_id = ui.generate_random()
    description = ui.get_input("Write position description: ")
    number_of_seat = ui.get_input("Enter the number of seats: ")
    company_id_position = ui.get_input("Enter company id: ")
    for i in data_manager.import_file("company.csv"):
        if i[0] == company_id_position:
            final_id = [ position_id, description, number_of_seat, company_id_position]
            data_manager.export_file(final_id, file_name, "a")
示例#8
0
def display_one():
    names = {'id': 'Id:'}
    user_data = ui.get_input(names=names)
    cleaned_data = recursively_validate(validator=IdValidator,
                                        data=user_data,
                                        names=names)
    db_data = db.one(id=cleaned_data['id'])
    ui.display_one(item=db_data)
示例#9
0
文件: views.py 项目: avinassh/UTFT
def display_one():
    names = {'id': 'Id:'}
    user_data = ui.get_input(names=names)
    cleaned_data = recursively_validate(validator=IdValidator,
                                        data=user_data,
                                        names=names)
    db_data = db.one(id=cleaned_data['id'])
    ui.display_one(item=db_data)
示例#10
0
def start_module(game_map):
    """ Loads the selected map (default if none given)
    Arguments: 
        game_map: a list in list with the selected map
    Returns:
        None, it just prints the map """
    win_zones = define_coords_of_searched_letter(game_map, "S")
    score_list = {"Steps": 0, "Push": 0}
    actual_map = game_map
    while True:
        check_win_condition(actual_map, win_zones)
        ui.print_table(actual_map, score_list)
        next_move = ui.get_input(["Make your move!, Q for exit"])
        while next_move[0] not in "wWaAsSdDqQ":
            next_move = ui.get_input(["Make your move!, Q for exit"])
        if next_move[0] == "q":
            return False
        actual_map = movement.movement(actual_map, str(next_move[0]))
示例#11
0
def update_application(table, file_name, application_ID):

    updated_status = ui.get_input("Enter updated status here: ")

    for i in table:
        if i[0] == application_ID:
            i[1] = updated_status

    data_manager.export_file(table, file_name, "w")
示例#12
0
def read_company(table, file_name):
    '''

    Users can show the details of existing companies by entering their ID.
    All “Position” of a company shows up here.'''
    company_id_by_user = ui.get_input("Enter a company id: ")
    for i in table:
        if i[0] == company_id_by_user:
            print(i)
示例#13
0
def create_company(table, file_name):
    '''

    Users can create new companies. Companies have an ID, name.
    IDs and names of companies are unique amongst other companies.'''
    company_id = ui.generate_random()
    company_name = ui.get_input("Enter your company name: ")
    company_datas = [company_id, company_name]
    data_manager.export_file(company_datas, file_name, "a")
示例#14
0
	def run(self):
		parser = OptionParser("%prog [options] [url_or_domain]")
		parser.add_option('-l', '--length', type='int', default=10, help='length of generated password (%default)')
		parser.add_option('--ask', action='store_true', default=False, help='Ask for the password, skipping system store (default is --no-ask)')
		parser.add_option('--no-ask', dest='ask', action='store_false')
		parser.add_option('--save', action='store_true', default=False, help='Save password (in system store, default is --no-save)')
		parser.add_option('--no-save', dest='save', action='store_false')
		parser.add_option('--notify', action='store_true', default=True, help='Notify on completion (default is --notify)')
		parser.add_option('-q', '--no-notify', dest='notify', action='store_false')
		parser.add_option('-r', '--remember', action='store_true', default=True, help='remember on completion (default is --remember)')
		parser.add_option('--no-remember', dest='remember', action='store_false')
		parser.add_option('--forget', action='store_true', default=False, help='forget this domain from ~/.supergenpass.domains (undo a previous --remember)')
		parser.add_option('--domains', dest='list_domains', action='store_true', default=False, help='list all remembered domains')
		parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='more information')
		parser.add_option('-p', '--print', dest='print_password', action='store_true', default=None, help='just print generated password')

		opts, args =  parser.parse_args()
		self.opts = opts
		if len(args) > 1:
			parser.print_help()
			sys.exit(1)
		else:
			url = args[0] if args else None

		if opts.list_domains:
			print '\n'.join(persistence.get_domains())
			return

		if opts.save:
			opts.ask = True

		if opts.print_password is None and not sys.stdout.isatty():
			if opts.verbose:
				print >> sys.stderr, "sgp: assuming --print since stdout is not a TTY"
			opts.print_password = True

		if not url:
			url = self.do(guess_url)
		if not url:
			url = ui.get_input('Enter domain / URL: ')

		pass_ = None
		if not opts.ask:
			try:
				pass_ = self.do(get_pass)
			except (StandardError): pass
		if not pass_:
			pass_ = ui.get_password('Enter master password: '******'t save password to os store: %s" % (e,)
				raise
示例#15
0
def get_time():  # from calendar
    try:
        time = int(ui.get_input('Enter start time'))
        if time in range(8, 19):
            return time
        else:
            raise TypeError
    except (TypeError, ValueError):
        print('seems like you typed time that\'s off your working hours')
def delete_album_from(albums):
    while True:
        music_reports.get_genre_list(albums)
        genre = ui.get_input('Enter genre or number: ')
        for album in albums:
            if genre == album[GENRE]:
                albums.remove(album)
            ui.display_messsge(
                ui.display_colored_text(CONFIRM_COLOR, 'Genre deleted'))
        else:
            ui.display_error_message("There isn't such genre!")
        break
示例#17
0
def new_book():
    """Get info from user, add new book"""
    new_book = ui.get_new_book_info()
    if datastore.check_duplicate(new_book.title,
                                 new_book.author):  #True if duplicate exists
        if ui.get_input(
                "Book with same title and author was already added.  To add anyway, type y."
        ).lower()[0] != "y":
            ui.message("entry canceled")
    else:
        datastore.add_book(new_book)
        ui.message('Book added: ' + str(new_book))
示例#18
0
def edit_meeting(table, items_to_edit):
    new_line = []
    new_line_option_list = [
        "Enter a new meeting title", "Enter a new duration in hours (1 or 2)",
        "Enter a new start time"
    ]
    for i in range(len(table)):
        if items_to_edit == table[i][STARTING_TIME]:
            new_line = ui.get_input(new_line_option_list,
                                    "Edit an existing meeting")
            table[i] = new_line
            storage.write_file_from_table("meetings.txt", table)
    return table
示例#19
0
def delete_position(table, file_name):

    position_id_by_user = ui.get_input("Enter position id: ")
    is_in_position = True
    for j in data_manager.import_file("application.csv"):
        if j[3] == position_id_by_user:
            is_in_position = False

    if is_in_position:
        for i in table:
            if i[0] == position_id_by_user:
                table.remove(i)
    data_manager.export_file(table, file_name, "w")
示例#20
0
def main():
    os.system('cls' if os.name == 'nt' else 'clear')
    main_menu()
    x = int(ui.get_input("Enter a number: "))
    if x == 1:
        student.start_module()
    if x == 2:
        company.start_module()
    if x == 3:
        position.start_module()
    if x == 4:
        application.start_module()
    else:
        os.sys.exit()
示例#21
0
文件: views.py 项目: avinassh/UTFT
def recursively_validate(validator, data, names):
    new_data = data.copy()
    while True:
        v = validator(data=new_data)
        if v.is_valid():
            break
        else:
            ui.display_block_sep()
            ui.display_errors(errors=v.errors)
            ui.display_block_sep()
            missing_names = {name: names[name] for name in v.errors}
            d = ui.get_input(names=missing_names)
            new_data.update(d)
    return new_data
示例#22
0
def main_menu():
    table = storage.get_table_from_file("meetings.txt")
    ui.print_table("Your schedule for the day", table)
    handle_menu()
    inputs = ui.get_input(["Your choise"], "")
    options = inputs[0]
    if options == "s":
        schedule_new_meeting(table)

    if options == "c":
        cancel_existing_meeting(table)

    if options == "e":
        starting_time_input = ui.get_input(
            ["Which meeting would you like to edit (starting time)"], "")
        items_to_edit = starting_time_input[0]
        edit_meeting(table, items_to_edit)

    if options == "q":
        sys.exit(0)

    else:
        ui.print_error_message("There is no such option.")
示例#23
0
def cancel_existing_meeting(table):
    labels_title = ["Enter the start time"]
    while True:
        inputs = ui.get_input(labels_title, "Cancel an existing meeting.")
        item_to_delete = inputs[0]
        if any(item_to_delete in i for i in table):
            for i in table:
                if i[STARTING_TIME] == item_to_delete:
                    table.remove(i)
                    storage.write_file_from_table("meetings.txt", table)
                    return table
        else:
            ui.print_error_message(
                "There is no meeting starting at that time!")
示例#24
0
def recursively_validate(validator, data, names):
    new_data = data.copy()
    while True:
        v = validator(data=new_data)
        if v.is_valid():
            break
        else:
            ui.display_block_sep()
            ui.display_errors(errors=v.errors)
            ui.display_block_sep()
            missing_names = {name: names[name] for name in v.errors}
            d = ui.get_input(names=missing_names)
            new_data.update(d)
    return new_data
示例#25
0
def get_duration():  # from calendar
    '''
    gets duration of the meeting, can only take values: 1 or 2
    '''

    try:
        duration = int(ui.get_input('Enter duration in hours (1 or 2)'))
    except ValueError:
        print('how about you type in a NUMBER?')
        get_duration()

    if duration in range(1, 3):
        return duration
    else:
        print('something went wrong, mate')
        get_duration()
示例#26
0
def cancel_meeting(meetings_list):
    '''
    asks user for the hour of the already existing meeting,
    then, based on that number, finds the meeting and deletes it
    '''
    print('Cancel an existing meeting.')
    hour_to_free = int(ui.get_input('Enter the start time'))
    print(meetings_list)
    for lst in meetings_list:
        print(lst)
        if hour_to_free == lst[0]:
            meetings_list.remove(lst)
            print('deleted\n\n')
            return meetings_list
        else:
            print('not scheduled anything on this time\n\n')
def search_by_type(games_list_of_lists):
    '''
    Wyszykuje i przedstawia gry określonego typu.
    '''
    inputs = ui.get_input("Search by type", ["Enter type to search"])
    type_of_game = inputs[0]
    result = []

    for game in games_list_of_lists:
        if game[5] == type_of_game:
            result.append(game)

    if len(result) < 1:
        ui.print_error_msg("Sorry, no such type!")
    else:
        ui.print_table(result)
示例#28
0
文件: views.py 项目: nijwiz/UTFT
def add():
    # Read details from user
    NAMES = {'first_name': 'First Name:', 'last_name': 'Last Name:',
             'email': 'Email:', 'phone': 'Phone:'}
    user_data = ui.get_input(names=NAMES)
    # User submitted the data, now validate till the fields are correct
    data = recursively_validate(validator=AddValidator, data=user_data,
                                names=NAMES)
    email = data.get('email')
    if email:
        # Call external service to get url
        data['thumbnail_path'] = fetch_gravatar_and_store(email=email)
    # Store to db
    db.add(data=data)
    # Call ui
    ui.add()
def search_by_title(games_list_of_lists):
    '''
    Wyszykuje wpis dla określonego tytułu.
    '''
    inputs = ui.get_input("Search by title", ["Enter title to search"])
    title = inputs[0]
    result = []

    for game in games_list_of_lists:
        if game[0] == title:
            result.append(game)

    if len(result) < 1:
        ui.print_error_msg("Sorry, no such title!")
    else:
        ui.print_table(result)
示例#30
0
def delete_company(table, file_name):
    '''

    Users can delete existing companies by entering their ID.
    Companies cannot be deleted if they have an existing “Position”.'''

    company_id_by_user = ui.get_input("Enter company id: ")
    is_in_position = True
    for j in data_manager.import_file("postion.csv"):
        if j[3] == company_id_by_user:
            is_in_position = False

    if is_in_position:
        for i in table:
            if i[0] == company_id_by_user:
                table.remove(i)
                data_manager.export_file(table, file_name, "w")
示例#31
0
def choose():
    inputs = ui.get_input(["Please enter a number: "])
    option = inputs[0]
    game_level = file_manager.get_table_from_file("map.csv")

    if option == "1":
        game.start_module(game_level)
    elif option == "2":
        game.select_level()
    elif option == "3":
        game.save_game()
    elif option == "4":
        game.load_game()
    elif option == "0":
        os.sys.exit(0)
    else:
        raise KeyError("There is no such option.")
示例#32
0
def user_choice(meetings, switch):

    new_data = [
    ]  # here all the data from this function is complied, so it can be used in other functions
    choice = ui.get_input(
        'Your choice'
    )  # just a friendly shortcut for input function from outside the module

    if choice == 's':
        meetings.append(schedule_new(new_data))

    elif choice == 'c':
        meetings = cancel_meeting(meetings)

    elif choice == 'q':
        switch = False
        return switch
示例#33
0
def question_mark(player, question, answer):
    import ui
    REWARD = 200
    LOST = -50
    user_answer = ui.get_input(question)
    if user_answer.upper() == answer:
        player.message = "Correct! Reward: 200 gold"
        player.show_message()
        player.add_money(REWARD)
        return True
    else:
        if player.money + LOST < 0:
            player.money = 0
            player.message = "Wrong! Hint can be helpful."
            player.show_message()
        else:
            player.add_money(LOST)
            player.message = "Wrong! You lost 50 gold. Hints can be helpful."
            player.show_message()
        return False
示例#34
0
def schedule_new_meeting(table):
    labels_title = [
        "Enter meeting title", "Enter duration in hours (1 or 2)",
        "Enter start time"
    ]
    while True:
        items_to_add = ui.get_input(labels_title, "Schedule a new meeting.")
        if valid_time_error(items_to_add, table) == True:
            ui.print_error_message(
                "Meeting is outside of your working hours (8 to 18)!")
            continue
        if already_used_time(items_to_add, table) == True:
            ui.print_error_message("Meeting overlaps with existing meeting!")
            continue
        if too_long_meeting(items_to_add, table) == True:
            ui.print_error_message("Duration is out of range!")
            continue
        else:
            table.append(items_to_add)
            storage.write_file_from_table("meetings.txt", table)
            return table
示例#35
0
	def run(self):
		parser = OptionParser("%prog [options] [url_or_domain]")
		parser.add_option('-l', '--length', type='int', default=10, help='length of generated password (%default)')
		parser.add_option('--ask', action='store_true', default=False, help='(ignored)')
		parser.add_option('--no-ask', dest='ask', action='store_false', help='(ignored)')
		parser.add_option('--save', action='store_true', default=False, help='(ignored)')
		parser.add_option('--no-save', dest='save', action='store_false', help='(ignored)')
		parser.add_option('--notify', action='store_true', default=True, help='Notify on completion (default is --notify)')
		parser.add_option('-q', '--no-notify', dest='notify', action='store_false')
		parser.add_option('-r', '--remember', action='store_true', default=True, help='remember on completion (default is --remember)')
		parser.add_option('--hint', help='add a hint for this domain (implies --remember)')
		parser.add_option('--no-remember', dest='remember', action='store_false')
		parser.add_option('--forget', action='store_true', default=False, help='forget this domain from ~/.config/supergenpass/domains (undo a previous --remember)')
		parser.add_option('--domains', dest='list_domains', action='store_true', default=False, help='list all remembered domains')
		parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='more information')
		parser.add_option('-p', '--print', dest='print_password', action='store_true', default=None, help='just print generated password')

		opts, args =  parser.parse_args()
		self.opts = opts
		if len(args) > 1:
			parser.print_help()
			sys.exit(1)
		else:
			url = args[0] if args else None

		store = persistence.load()
		if opts.list_domains:
			print('\n'.join(store.list_domains()))
			return

		if not url:
			url = self.do(guess_url)
		if not url:
			url = ui.get_input('Enter domain / URL: ')

		domain = url_to_domain(url)
		info("Using Domain: %s" % (domain,))

		if opts.forget:
			store.forget(domain)
		elif opts.hint is not None:
			store.remember(domain, opts.hint)
		else:
			if opts.print_password is None and not sys.stdout.isatty():
				if opts.verbose:
					info("sgp: assuming --print since stdout is not a TTY")
				opts.print_password = True

			current_hint = store.get_hint(domain)
			if current_hint:
				info("(Hint: %s)" % (current_hint,))

			pass_ = ui.get_password('Enter master password: '******'%s'" % (opts.length, domain))
				try:
					save_clipboard(generated_pass)
					info("  (password saved to the clipboard)")
				except (StandardError, ImportError):
					if opts.verbose:
						import traceback
						traceback.print_exc()
					info("could not save clipboard. your password is: %s" % (generated_pass))
			if opts.notify:
				self.do(notify, domain)
			if opts.remember:
				store.remember(domain)
		store.save()
示例#36
0
    def run(self):
        parser = OptionParser("%prog [options] [url_or_domain]")
        parser.add_option("-l", "--length", type="int", default=10, help="length of generated password (%default)")
        parser.add_option(
            "--ask",
            action="store_true",
            default=False,
            help="Ask for the password, skipping system store (default is --no-ask)",
        )
        parser.add_option("--no-ask", dest="ask", action="store_false")
        parser.add_option(
            "--save", action="store_true", default=False, help="Save password (in system store, default is --no-save)"
        )
        parser.add_option("--no-save", dest="save", action="store_false")
        parser.add_option(
            "--notify", action="store_true", default=True, help="Notify on completion (default is --notify)"
        )
        parser.add_option("-q", "--no-notify", dest="notify", action="store_false")
        parser.add_option(
            "-r", "--remember", action="store_true", default=True, help="remember on completion (default is --remember)"
        )
        parser.add_option("--no-remember", dest="remember", action="store_false")
        parser.add_option(
            "--forget",
            action="store_true",
            default=False,
            help="forget this domain from ~/.supergenpass.domains (undo a previous --remember)",
        )
        parser.add_option(
            "--domains", dest="list_domains", action="store_true", default=False, help="list all remembered domains"
        )
        parser.add_option(
            "-p",
            "--print",
            dest="print_password",
            action="store_true",
            default=False,
            help="just print generated password",
        )

        opts, args = parser.parse_args()
        if len(args) > 1:
            parser.print_help()
            sys.exit(1)
        else:
            url = args[0] if args else None

        if opts.list_domains:
            print "\n".join(persistence.get_domains())
            return

        if opts.save:
            opts.ask = True

        if not url:
            url = self.do(guess_url)
        if not url:
            url = ui.get_input("Enter domain / URL: ")

        pass_ = None
        if not opts.ask:
            try:
                pass_ = self.do(get_pass)
            except RuntimeError:
                pass
        if not pass_:
            pass_ = ui.get_password("Enter master password: "******"not supported by os integration module"
            except RuntimeError, e:
                print "Couldn't save password to os store: %s" % (e,)
                raise