ó
ž^Yc           @@  sŁ   d  Z  d d l m Z d Z d g Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z d d	 l m Z d d
 l m Z d g  d d  Z d S(   sd   Utilities for making samples.

Consolidates a lot of code commonly repeated in sample applications.
i    (   t   absolute_imports$   jcgregorio@google.com (Joe Gregorio)t   initN(   t	   discovery(   t
   build_http(   t   client(   t   file(   t   toolsc      
   C@  ss  | d k r d | } n  t j g } | j |  t j d | d t j d |  }	 |	 j |  d  }
 t j	 j
 t j	 j |  d  } t j | d | d t j |  } t j | d	  } | j   } | d k sß | j r÷ t j | | |
  } n  | j d
 t    } | d k r3t j | | d
 | } n6 t |  ( } t j | j   d d d
 | } Wd QX| |
 f S(   sD  A common initialization routine for samples.

  Many of the sample applications do the same initialization, which has now
  been consolidated into this function. This function uses common idioms found
  in almost all the samples, i.e. for an API with name 'apiname', the
  credentials are stored in a file named apiname.dat, and the
  client_secrets.json file is stored in the same directory as the application
  main file.

  Args:
    argv: list of string, the command-line parameters of the application.
    name: string, name of the API.
    version: string, version of the API.
    doc: string, description of the application. Usually set to __doc__.
    file: string, filename of the application. Usually set to __file__.
    parents: list of argparse.ArgumentParser, additional command-line flags.
    scope: string, The OAuth scope used.
    discovery_filename: string, name of local discovery file (JSON). Use when discovery doc not available via URL.

  Returns:
    A tuple of (service, flags), where service is the service object and flags
    is the parsed command-line flags.
  s    https://www.googleapis.com/auth/t   descriptiont   formatter_classt   parentsi   s   client_secrets.jsont   scopet   messages   .datt   httpt   bases   https://www.googleapis.com/N(   t   NoneR   t	   argparsert   extendt   argparset   ArgumentParsert   RawDescriptionHelpFormattert
   parse_argst   ost   patht   joint   dirnameR   t   flow_from_clientsecretst   message_if_missingR   t   Storaget   gett   invalidt   run_flowt	   authorizeR   R   t   buildt   opent   build_from_documentt   read(   t   argvt   namet   versiont   doct   filenameR
   R	   t   discovery_filenamet   parent_parserst   parsert   flagst   client_secretst   flowt   storaget   credentialsR   t   servicet   discovery_file(    (    sN   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/sample_tools.pyR   #   s6    				(   t   __doc__t
   __future__R    t
   __author__t   __all__R   R   t   googleapiclientR   t   googleapiclient.httpR   t   oauth2clientR   R   R   R   R   (    (    (    sN   /tmp/pip-build-kpPAdC/google-api-python-client/googleapiclient/sample_tools.pyt   <module>   s   	