当前位置: 首页>>代码示例>>Python>>正文


Python argv.index方法代码示例

本文整理汇总了Python中sys.argv.index方法的典型用法代码示例。如果您正苦于以下问题:Python argv.index方法的具体用法?Python argv.index怎么用?Python argv.index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys.argv的用法示例。


在下文中一共展示了argv.index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_usermap

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def create_usermap(connection, obj, index=False):
    """
    Creates a mapping of all the user_ids that occur in OBJ to
    their full user objects (names, profile info, etc). Can
    be a thread_index or a messages object from one.
    """
    user_set = {item["author"] for item in obj}
    if index:
        [user_set.add(item["last_author"]) for item in obj]
    return {
        user_id: db.user_resolve(
            connection,
            user_id,
            externalize=True,
            return_false=False)
        for user_id in user_set
    } 
开发者ID:bbj-dev,项目名称:bbj,代码行数:19,代码来源:server.py

示例2: set_default_footer

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def set_default_footer(self, clobber_composer=False):
        """
        Sets the footer to the default for the current screen.
        """
        if self.window_split and not clobber_composer:
            return

        elif self.mode == "thread":
            footer = bars["thread"] % self.prefs["jump_count"]
            if self.match_data["matches"]:
                footer += " [@#] Search Control"

        else:
            footer = bars["index"]

        self.set_footer(footer) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:18,代码来源:main.py

示例3: thread_load

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def thread_load(self, button, thread_id):
        """
        Open a thread.
        """
        if app.mode == "index":
            # make sure the index goes back to this selected thread
            pos = self.get_focus_post(return_widget=True)
            self.last_index_pos = pos.thread["thread_id"]

        if not self.window_split:
            self.body.attr_map = {None: "default"}

        self.mode = "thread"
        thread, usermap = network.thread_load(thread_id, format="sequential")
        self.usermap.update(usermap)
        self.thread = thread
        self.match_data["matches"].clear()
        self.walker.clear()
        for message in thread["messages"]:
            self.walker += self.make_message_body(message)
        self.set_default_header()
        self.set_default_footer()
        self.goto_post(mark(thread_id)) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:25,代码来源:main.py

示例4: search_prompt

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def search_prompt(self):
        if self.mode == "index":
            callback = self.search_index_callback
        elif self.mode == "thread":
            callback = self.search_thread_callback
        else:
            return

        popup = OptionsMenu(
            urwid.ListBox(
                urwid.SimpleFocusListWalker([
                    urwid.Text(("button", "Enter a query:")),
                    urwid.AttrMap(StringPrompt(callback), "opt_prompt"),
                    urwid.Text("Use a blank query to reset the {}.".format(self.mode))
                ])),
            **self.frame_theme())

        self.loop.widget = urwid.Overlay(
            popup, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 25 if self.window_split else 50),
            width=("relative", 40), height=6) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:24,代码来源:main.py

示例5: main

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def main():
    flags = ['-l', '-load-file-path']
    for flag in flags:
        if flag in argv:
            load_flag = 1
            try:
                load_file_base_path = argv[argv.index(flag)+1]
                globals()['load_file_base_path'] = load_file_base_path
                load_file('start')
                break
            except:
                try:
                    exit('[-] Load file url/path error')
                except:
                    exit(0)
        else:
            load_flag = 0
    if not load_flag:exit("[-] %s need a url to load start.py, use '-l' or '--load-file-path' to set the load_file_path"%(argv[0].replace('.py', ''))) 
开发者ID:WyAtu,项目名称:Perun,代码行数:20,代码来源:Perun.py

示例6: is_wheel_for_windows

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def is_wheel_for_windows():
    if "bdist_wheel" in argv:
        names = ["win32", "win-amd64", "cygwin"]
        length = len(argv)
        for pos in range(argv.index("bdist_wheel") + 1, length):
            if argv[pos] == "--plat-name" and pos + 1 < length:
                return argv[pos + 1] in names
            elif argv[pos][:12] == "--plat-name=":
                return argv[pos][12:] in names
    return False 
开发者ID:streamlink,项目名称:streamlink,代码行数:12,代码来源:setup.py

示例7: get_arg

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def get_arg(key, default, get_value=True):
    try:
        spec = argv.index("--" + key)
        value = argv[spec + 1] if get_value else True
    except ValueError:  # --key not specified
        value = default
    except IndexError:  # flag given but no value
        exit("invalid format for --" + key)
    return value 
开发者ID:bbj-dev,项目名称:bbj,代码行数:11,代码来源:server.py

示例8: get_arg

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def get_arg(key, default=None, get_value=True):
    try:
        spec = argv.index("--" + key)
        value = argv[spec + 1] if get_value else True
    except ValueError: # --key not specified
        value = default
    except IndexError: # flag given but no value
        exit("invalid format for --" + key)
    return value 
开发者ID:bbj-dev,项目名称:bbj,代码行数:11,代码来源:main.py

示例9: deletion_dialog

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def deletion_dialog(self, button, message):
        """
        Prompts the user to confirm deletion of an item.
        This can delete either a thread or a post.
        """
        op = message["post_id"] == 0
        buttons = [
            urwid.Text(("bold", "Delete this %s?" % ("whole thread" if op else "post"))),
            urwid.Divider(),
            cute_button(("10" , ">> Yes"), lambda _: [
                network.message_delete(message["thread_id"], message["post_id"]),
                self.remove_overlays(),
                self.index() if op else self.refresh()
            ]),
            cute_button(("30", "<< No"), self.remove_overlays)
        ]

        # TODO: create a central routine for creating popups. this is getting really ridiculous
        popup = OptionsMenu(
            urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
            **self.frame_theme())

        self.loop.widget = urwid.Overlay(
            popup, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            width=30, height=6) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:29,代码来源:main.py

示例10: make_message_body

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def make_message_body(self, message, no_action=False):
        """
        Returns the widgets that comprise a message in a thread, including the
        text body, author info and the action button. Unlike the thread objects
        used in the index, this is not a pile widget, because using a pile
        causes line-by-line text scrolling to be unusable.
        """
        info = "@ " + self.timestring(message["created"])
        if message["edited"]:
            info += " [edited]"

        if no_action:
            callback = ignore
            name = urwid_rainbows("~SYSTEM", True)
            color = "0"
        else:
            callback = self.on_post
            name = urwid.Text("~{}".format(self.usermap[message["author"]]["user_name"]))
            color = str(self.usermap[message["author"]]["color"])

        post = str(message["post_id"])
        head = urwid.Columns([
                (2 + len(post), urwid.AttrMap(
                    cute_button(">" + post, callback, message), "button", "hover")),
                (len(name._text) + 1, urwid.AttrMap(name, color)),
                urwid.AttrMap(urwid.Text(info), "dim")
            ])

        head.message = message
        return [
            head,
            urwid.Divider(),
            urwid.Padding(
                MessageBody(message),
                width=self.prefs["max_text_width"]),
            urwid.Divider(),
            urwid.AttrMap(urwid.Divider(self.theme["divider"]), "dim")
        ] 
开发者ID:bbj-dev,项目名称:bbj,代码行数:40,代码来源:main.py

示例11: toggle_client_pin

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def toggle_client_pin(self):
        if self.mode != "index":
            return
        thread_id = self.walker.get_focus()[0].thread["thread_id"]
        self.client_pinned_threads = toggle_client_pin(thread_id)
        self.index() 
开发者ID:bbj-dev,项目名称:bbj,代码行数:8,代码来源:main.py

示例12: toggle_server_pin

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def toggle_server_pin(self):
        if self.mode != "index" or not network.user["is_admin"]:
            return
        thread = self.walker.get_focus()[0].thread
        network.thread_set_pin(thread["thread_id"], not thread["pinned"])
        self.index() 
开发者ID:bbj-dev,项目名称:bbj,代码行数:8,代码来源:main.py

示例13: do_search_result

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def do_search_result(self, forward=True):
        if not self.match_data["matches"]:
            return
        self.match_data["position"] += 1 if forward else -1
        length = len(self.match_data["matches"])
        if forward:
            if self.match_data["position"] == length:
                self.match_data["position"] = 0
        else:
            if self.match_data["position"] == -1:
                self.match_data["position"] = length - 1
        self.goto_post(self.match_data["matches"][self.match_data["position"]]["post_id"])
        self.temp_footer_message(
            "({}/{}) Searching for {} [#]Next [@]Previous".format(
                self.match_data["position"] + 1, length, self.match_data["query"]
            ), 5)


    # XXX: Try to find a way to overlay properties onto an existing widget instead of this trainwreck.
    # def highlight_query(self):
    #     # pass
    #     query = self.match_data["query"]
    #     for match in self.match_data["matches"]:
    #         widget = self.walker[match["post_id"] * 5 + 2].base_widget
    #         # (">>OP\n\nThat's a nice initiative x)", [('50', 4), (None, 2), ('default', 27)])
    #         text, attrs = widget.get_text()
    #         spans = [m.span() for m in re.finditer(query, text)]
    #         start, end = spans.pop(0)
    #         new_attrs = []
    #         index = 0
    #         for prop, length in attrs:
    #             if index and index > start:
    #                 index = end
    #                 new_attrs.append(("20", end - start))
    #                 start, end = spans.pop(0)
    #             else:
    #                 index += length
    #                 new_attrs.append((prop, length)) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:40,代码来源:main.py

示例14: refresh

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def refresh(self):
        self.remove_overlays()
        if self.mode == "index":
            # check to make sure there are any posts
            if self.walker:
                self.last_index_pos = self.get_focus_post(True).thread["thread_id"]
            self.index()
        else:
            mark()
            thread = self.thread["thread_id"]
            self.thread_load(None, thread)
            self.goto_post(mark(thread))
        self.temp_footer_message("Refreshed content!", 1) 
开发者ID:bbj-dev,项目名称:bbj,代码行数:15,代码来源:main.py

示例15: back

# 需要导入模块: from sys import argv [as 别名]
# 或者: from sys.argv import index [as 别名]
def back(self, terminate=False):
        if app.mode == "index" and terminate:
            frilly_exit()

        elif self.overlay_p():
            self.loop.widget = self.loop.widget[0]

        elif self.window_split:
            # display a confirmation dialog before killing off an in-progress post
            buttons = [
                urwid.Text(("bold", "Discard current post?")),
                urwid.Divider(),
                cute_button(("10" , ">> Yes"), lambda _: [
                    self.remove_overlays(),
                    self.index()
                ]),
                cute_button(("30", "<< No"), self.remove_overlays)
            ]

            # TODO: create a central routine for creating popups. this is getting really ridiculous
            popup = OptionsMenu(
                urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
                **self.frame_theme())

            self.loop.widget = urwid.Overlay(
                popup, self.loop.widget,
                align=("relative", 50),
                valign=("relative", 25),
                width=30, height=6)

        else:
            mark()
            self.index() 
开发者ID:bbj-dev,项目名称:bbj,代码行数:35,代码来源:main.py


注:本文中的sys.argv.index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。