🔍 Code Extractor

function main_v10

Maturity: 46

Entry point function that initializes and serves the CDocs Panel web application with configurable port and debug mode options.

File:
/tf/active/vicechatdev/cdocs_panel_app.py
Lines:
135 - 156
Complexity:
moderate

Purpose

This function serves as the main entry point for the CDocs Panel application. It parses command-line arguments for port configuration and debug mode, instantiates the CDocsApp class, retrieves the Panel application object, and serves it either in debug mode (with auto-show) or production mode (as servable). It's designed to be called when running the application as a standalone script.

Source Code

def main():
    """Main entry point for the CDocs Panel application."""
    # Parse command line arguments
    parser = argparse.ArgumentParser(description='CDocs Panel Application')
    parser.add_argument('--port', type=int, default=5006, help='Port to serve the application on')
    parser.add_argument('--debug', action='store_true', help='Run in debug mode')
    args = parser.parse_args()
    
    # Create the application
    app = CDocsApp()
    
    # Set up the panel app
    panel_app = app.get_app()
    
    # Serve the application
    if args.debug:
        pn.serve(panel_app, port=args.port, show=True)
    else:
        panel_app.servable()
        
    # Print serving information
    logger.info(f"CDocs Panel App serving on port {args.port}")

Return Value

This function does not return any value (implicitly returns None). Its purpose is to start and serve the Panel application, which runs as a blocking operation in debug mode or sets up the application as servable in production mode.

Dependencies

  • panel
  • param
  • pandas
  • argparse
  • logging
  • os
  • sys
  • datetime
  • CDocs.ui.components
  • CDocs.ui.auth
  • CDocs.initialize_system
  • CDocs

Required Imports

import panel as pn
import param
import pandas as pd
import os
import sys
import logging
from datetime import datetime
import argparse
from CDocs.ui.components import DocumentListView
from CDocs.ui.components import DocumentDetailView
from CDocs.ui.components import ReviewListView
from CDocs.ui.components import ApprovalListView
from CDocs.ui.auth import AuthManager
from CDocs.initialize_system import initialize_system
from CDocs import __version__

Usage Example

# Assuming this is in a file called app.py with CDocsApp defined
import panel as pn
import argparse
import logging

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

class CDocsApp:
    def get_app(self):
        return pn.Column('# CDocs Application', 'Welcome to CDocs')

def main():
    parser = argparse.ArgumentParser(description='CDocs Panel Application')
    parser.add_argument('--port', type=int, default=5006, help='Port to serve the application on')
    parser.add_argument('--debug', action='store_true', help='Run in debug mode')
    args = parser.parse_args()
    
    app = CDocsApp()
    panel_app = app.get_app()
    
    if args.debug:
        pn.serve(panel_app, port=args.port, show=True)
    else:
        panel_app.servable()
        
    logger.info(f"CDocs Panel App serving on port {args.port}")

if __name__ == '__main__':
    main()

# Run from command line:
# python app.py --port 5006 --debug
# or
# python app.py --port 8080

Best Practices

  • This function should be called from a if __name__ == '__main__': block to ensure it only runs when the script is executed directly
  • Ensure the logger is properly configured before calling this function to capture startup information
  • The CDocsApp class must be defined or imported before calling main()
  • In production environments, avoid using --debug flag as it opens a browser window automatically
  • When using panel_app.servable(), ensure the script is run with 'panel serve' command rather than direct Python execution
  • The port specified must not be in use by another application
  • Consider adding exception handling around pn.serve() for production deployments
  • Ensure all CDocs dependencies and modules are properly installed before running

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class CDocsApp 66.0% similar

    Panel application for the CDocs Controlled Document System. This class provides a complete Panel application with navigation, user authentication, and all document management features.

    From: /tf/active/vicechatdev/cdocs_panel_app.py
  • function main_v7 64.2% similar

    Main entry point for a Streamlit-based FileCloud Data Processor application that handles authentication, session state management, and navigation between multiple modules including document audit, controlled documents, settings, and reports.

    From: /tf/active/vicechatdev/datacapture_integrated.py
  • function main_v14 62.2% similar

    Entry point function that orchestrates the Project Victoria disclosure analysis by initializing the generator, running the complete analysis, and displaying results with next steps.

    From: /tf/active/vicechatdev/project_victoria_disclosure_generator.py
  • function main_v9 60.5% similar

    Main entry point for a SharePoint to FileCloud synchronization application that handles command-line arguments, connection testing, and orchestrates single or continuous sync operations.

    From: /tf/active/vicechatdev/SPFCsync/main.py
  • class ControlledDocApp 60.2% similar

    A standalone Panel web application class that provides a complete controlled document management system with user authentication, navigation, and document lifecycle management features.

    From: /tf/active/vicechatdev/panel_app.py
← Back to Browse