idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
245,300 | def load_views ( self ) : view_path = os . path . join ( self . path , StatikProject . VIEWS_DIR ) logger . debug ( "Loading views from: %s" , view_path ) if not os . path . isdir ( view_path ) : raise MissingProjectFolderError ( StatikProject . VIEWS_DIR ) view_files = list_files ( view_path , [ 'yml' , 'yaml' ] ) log... | Loads the views for this project from the project directory structure . | 219 | 13 |
245,301 | def process_views ( self ) : output = { } logger . debug ( "Processing %d view(s)..." , len ( self . views ) ) for view_name , view in iteritems ( self . views ) : try : output = deep_merge_dict ( output , view . process ( self . db , safe_mode = self . safe_mode , extra_context = self . project_context ) ) except Stat... | Processes the loaded views to generate the required output data . | 154 | 12 |
245,302 | def dump_in_memory_result ( self , result , output_path ) : file_count = 0 logger . debug ( "Dumping in-memory processing results to output folder: %s" , output_path ) for k , v in iteritems ( result ) : cur_output_path = os . path . join ( output_path , k ) if isinstance ( v , dict ) : file_count += self . dump_in_mem... | Recursively dumps the result of our processing into files within the given output path . | 204 | 17 |
245,303 | def copy_assets ( self , output_path ) : src_paths = [ ] # if we have a theme if self . config . theme is not None : # assume it's in the folder: "themes/theme_name/assets" src_paths . append ( os . path . join ( self . path , StatikProject . THEMES_DIR , self . config . theme , StatikProject . ASSETS_DIR ) ) # NOTE: A... | Copies all asset files from the source path to the destination path . If no such source path exists no asset copying will be performed . | 377 | 27 |
245,304 | def autogen ( project_path ) : generate_quickstart ( project_path ) project = StatikProject ( project_path ) project . config = StatikConfig ( project . config_file_path ) models = list ( project . load_models ( ) . values ( ) ) logger . info ( 'Creating view and template for home page (index.html).' ) generate_yaml_fi... | Autogenerates views and templates for all the models in the project . | 367 | 15 |
245,305 | def generate_yaml_file ( filename , contents ) : with open ( filename , 'w' ) as file : file . write ( yaml . dump ( contents , default_flow_style = False ) ) | Creates a yaml file with the given content . | 45 | 11 |
245,306 | def generate_index_file ( filename ) : with open ( filename , 'w' ) as file : content = open ( os . path . join ( os . path . dirname ( __file__ ) , 'templates/index_page.html' ) , 'r' ) . read ( ) file . write ( content ) | Constructs a default home page for the project . | 70 | 10 |
245,307 | def generate_model_file ( filename , project , model , fields ) : for field in fields : field . type = field . __class__ . __name__ content = open ( os . path . join ( os . path . dirname ( __file__ ) , 'templates/model_page.html' ) , 'r' ) . read ( ) engine = StatikTemplateEngine ( project ) template = engine . create... | Creates a webpage for a given instance of a model . | 160 | 12 |
245,308 | def build_dynamic ( self , db , extra = None , safe_mode = False ) : result = dict ( ) for var , query in iteritems ( self . dynamic ) : result [ var ] = db . query ( query , safe_mode = safe_mode , additional_locals = extra ) return result | Builds the dynamic context based on our current dynamic context entity and the given database . | 67 | 17 |
245,309 | def build_for_each ( self , db , safe_mode = False , extra = None ) : result = dict ( ) for var , query in iteritems ( self . for_each ) : result [ var ] = db . query ( query , additional_locals = extra , safe_mode = safe_mode ) return result | Builds the for - each context . | 70 | 8 |
245,310 | def build ( self , db = None , safe_mode = False , for_each_inst = None , extra = None ) : result = copy ( self . initial ) result . update ( self . static ) if self . dynamic : result . update ( self . build_dynamic ( db , extra = extra , safe_mode = safe_mode ) ) if self . for_each and for_each_inst : result . update... | Builds a dictionary that can be used as context for template rendering . | 132 | 14 |
245,311 | def template_exception_handler ( fn , error_context , filename = None ) : error_message = None if filename : error_context . update ( filename = filename ) try : return fn ( ) except jinja2 . TemplateSyntaxError as exc : error_context . update ( filename = exc . filename , line_no = exc . lineno ) error_message = exc .... | Calls the given function attempting to catch any template - related errors and converts the error to a Statik TemplateError instance . Returns the result returned by the function itself . | 132 | 34 |
245,312 | def create_template ( self , s , provider_name = None ) : if provider_name is None : provider_name = self . supported_providers [ 0 ] return template_exception_handler ( lambda : self . get_provider ( provider_name ) . create_template ( s ) , self . error_context ) | Creates a template from the given string based on the specified provider or the provider with highest precedence . | 71 | 20 |
245,313 | def construct_field ( model_name , field_name , field_type , all_models , * * kwargs ) : field_type_parts = field_type . split ( '->' ) _field_type = field_type_parts [ 0 ] . strip ( ) . split ( '[]' ) [ 0 ] . strip ( ) back_populates = field_type_parts [ 1 ] . strip ( ) if len ( field_type_parts ) > 1 else None error_... | Helper function to build a field from the given field name and type . | 303 | 14 |
245,314 | def paginate ( db_query , items_per_page , offset = 0 , start_page = 1 ) : return Paginator ( db_query , items_per_page , offset = offset , start_page = start_page ) | Instantiates a Paginator instance for database queries . | 51 | 11 |
245,315 | def render_reverse ( self , inst = None , context = None ) : rendered = self . render ( inst = inst , context = context ) parts = rendered . split ( '/' ) # we only prettify URLs for these files if parts [ - 1 ] in [ 'index.html' , 'index.htm' ] : return ( '/' . join ( parts [ : - 1 ] ) ) + '/' return rendered | Renders the reverse URL for this path . | 89 | 9 |
245,316 | def create ( cls , path , template_engine = None , output_filename = None , output_ext = None , view_name = None ) : # if it's a complex view if isinstance ( path , dict ) : return StatikViewComplexPath ( path , template_engine , output_filename = output_filename , output_ext = output_ext , view_name = view_name ) elif... | Create the relevant subclass of StatikView based on the given path variable and parameters . | 159 | 17 |
245,317 | def render ( self , context , db = None , safe_mode = False , extra_context = None ) : if not db : raise MissingParameterError ( "db" , context = self . error_context ) rendered_views = dict ( ) path_instances = db . query ( self . path . query , safe_mode = safe_mode ) extra_ctx = copy ( extra_context ) if extra_conte... | Renders the given context using the specified database returning a dictionary containing path segments and rendered view contents . | 220 | 20 |
245,318 | def render ( self , db , safe_mode = False , extra_context = None ) : return self . renderer . render ( self . context , db , safe_mode = safe_mode , extra_context = extra_context ) | Renders this view given the specified StatikDatabase instance . | 50 | 12 |
245,319 | def _validate_number_of_layers ( self , number_of_layers ) : # Only positive numbers are correct if number_of_layers <= 0 : raise SquashError ( "Number of layers to squash cannot be less or equal 0, provided: %s" % number_of_layers ) # Do not squash if provided number of layer to squash is bigger # than number of actua... | Makes sure that the specified number of layers to squash is a valid number | 160 | 15 |
245,320 | def _files_in_layers ( self , layers , directory ) : files = { } for layer in layers : self . log . debug ( "Generating list of files in layer '%s'..." % layer ) tar_file = os . path . join ( directory , layer , "layer.tar" ) with tarfile . open ( tar_file , 'r' , format = tarfile . PAX_FORMAT ) as tar : files [ layer ... | Prepare a list of files in all layers | 145 | 9 |
245,321 | def _prepare_tmp_directory ( self , tmp_dir ) : if tmp_dir : if os . path . exists ( tmp_dir ) : raise SquashError ( "The '%s' directory already exists, please remove it before you proceed" % tmp_dir ) os . makedirs ( tmp_dir ) else : tmp_dir = tempfile . mkdtemp ( prefix = "docker-squash-" ) self . log . debug ( "Usin... | Creates temporary directory that is used to work on layers | 116 | 11 |
245,322 | def _layers_to_squash ( self , layers , from_layer ) : to_squash = [ ] to_leave = [ ] should_squash = True for l in reversed ( layers ) : if l == from_layer : should_squash = False if should_squash : to_squash . append ( l ) else : to_leave . append ( l ) to_squash . reverse ( ) to_leave . reverse ( ) return to_squash ... | Prepares a list of layer IDs that should be squashed | 108 | 12 |
245,323 | def _save_image ( self , image_id , directory ) : for x in [ 0 , 1 , 2 ] : self . log . info ( "Saving image %s to %s directory..." % ( image_id , directory ) ) self . log . debug ( "Try #%s..." % ( x + 1 ) ) try : image = self . docker . get_image ( image_id ) if docker . version_info [ 0 ] < 3 : # Docker library prio... | Saves the image as a tar archive under specified name | 373 | 11 |
245,324 | def _unpack ( self , tar_file , directory ) : self . log . info ( "Unpacking %s tar file to %s directory" % ( tar_file , directory ) ) with tarfile . open ( tar_file , 'r' ) as tar : tar . extractall ( path = directory ) self . log . info ( "Archive unpacked!" ) | Unpacks tar archive to selected directory | 80 | 7 |
245,325 | def _parse_image_name ( self , image ) : if ':' in image and '/' not in image . split ( ':' ) [ - 1 ] : image_tag = image . split ( ':' ) [ - 1 ] image_name = image [ : - ( len ( image_tag ) + 1 ) ] else : image_tag = "latest" image_name = image return ( image_name , image_tag ) | Parses the provided image name and splits it in the name and tag part if possible . If no tag is provided latest is used . | 93 | 28 |
245,326 | def _dump_json ( self , data , new_line = False ) : # We do not want any spaces between keys and values in JSON json_data = json . dumps ( data , separators = ( ',' , ':' ) ) if new_line : json_data = "%s\n" % json_data # Generate sha256sum of the JSON data, may be handy sha = hashlib . sha256 ( json_data . encode ( 'u... | Helper function to marshal object into JSON string . Additionally a sha256sum of the created JSON string is generated . | 120 | 24 |
245,327 | def _move_layers ( self , layers , src , dest ) : for layer in layers : layer_id = layer . replace ( 'sha256:' , '' ) self . log . debug ( "Moving unmodified layer '%s'..." % layer_id ) shutil . move ( os . path . join ( src , layer_id ) , dest ) | This moves all the layers that should be copied as - is . In other words - all layers that are not meant to be squashed will be moved from the old image to the new image untouched . | 77 | 40 |
245,328 | def _marker_files ( self , tar , members ) : marker_files = { } self . log . debug ( "Searching for marker files in '%s' archive..." % tar . name ) for member in members : if '.wh.' in member . name : self . log . debug ( "Found '%s' marker file" % member . name ) marker_files [ member ] = tar . extractfile ( member ) ... | Searches for marker files in the specified archive . | 118 | 11 |
245,329 | def _add_markers ( self , markers , tar , files_in_layers , added_symlinks ) : if markers : self . log . debug ( "Marker files to add: %s" % [ o . name for o in markers . keys ( ) ] ) else : # No marker files to add return # https://github.com/goldmann/docker-squash/issues/108 # Some tar archives do have the filenames ... | This method is responsible for adding back all markers that were not added to the squashed layer AND files they refer to can be found in layers we do not squash . | 532 | 33 |
245,330 | def _proc_pax ( self , filetar ) : # Read the header information. buf = filetar . fileobj . read ( self . _block ( self . size ) ) # A pax header stores supplemental information for either # the following file (extended) or all following files # (global). if self . type == tarfile . XGLTYPE : pax_headers = filetar . pa... | Process an extended or global header as described in POSIX . 1 - 2001 . | 496 | 16 |
245,331 | def _create_pax_generic_header ( cls , pax_headers , type = tarfile . XHDTYPE ) : records = [ ] for keyword , value in pax_headers . iteritems ( ) : try : keyword = keyword . encode ( "utf8" ) except Exception : pass try : value = value . encode ( "utf8" ) except Exception : pass l = len ( keyword ) + len ( value ) + 3... | Return a POSIX . 1 - 2001 extended or global header sequence that contains a list of keyword value pairs . The values must be unicode objects . | 288 | 30 |
245,332 | def _read_json_file ( self , json_file ) : self . log . debug ( "Reading '%s' JSON file..." % json_file ) with open ( json_file , 'r' ) as f : return json . load ( f , object_pairs_hook = OrderedDict ) | Helper function to read JSON file as OrderedDict | 68 | 11 |
245,333 | def _read_layer_paths ( self , old_image_config , old_image_manifest , layers_to_move ) : # In manifest.json we do not have listed all layers # but only layers that do contain some data. current_manifest_layer = 0 layer_paths_to_move = [ ] layer_paths_to_squash = [ ] # Iterate over image history, from base image to top... | In case of v2 format layer id s are not the same as the id s used in the exported tar archive to name directories for layers . These id s can be found in the configuration files saved with the image - we need to read them . | 273 | 50 |
245,334 | def _generate_squashed_layer_path_id ( self ) : # Using OrderedDict, because order of JSON elements is important v1_metadata = OrderedDict ( self . old_image_config ) # Update image creation date v1_metadata [ 'created' ] = self . date # Remove unnecessary elements # Do not fail if key is not found for key in 'history'... | This function generates the id used to name the directory to store the squashed layer content in the archive . | 459 | 21 |
245,335 | def write_local_file ( self , outputfile , path ) : self . logger . info ( "Writing file to %s" , path ) outputfile . seek ( 0 ) with open ( path , 'wb' ) as fd : copyfileobj ( outputfile , fd ) | Write file to the desired path . | 61 | 7 |
245,336 | def _cleanup_old_backups ( self , database = None , servername = None ) : self . storage . clean_old_backups ( encrypted = self . encrypt , compressed = self . compress , content_type = self . content_type , database = database , servername = servername ) | Cleanup old backups keeping the number of backups specified by DBBACKUP_CLEANUP_KEEP and any backups that occur on first of the month . | 68 | 33 |
245,337 | def _save_new_backup ( self , database ) : self . logger . info ( "Backing Up Database: %s" , database [ 'NAME' ] ) # Get backup and name filename = self . connector . generate_filename ( self . servername ) outputfile = self . connector . create_dump ( ) # Apply trans if self . compress : compressed_file , filename = ... | Save a new backup file . | 219 | 6 |
245,338 | def _explore_storage ( self ) : path = '' dirs = [ path ] while dirs : path = dirs . pop ( ) subdirs , files = self . media_storage . listdir ( path ) for media_filename in files : yield os . path . join ( path , media_filename ) dirs . extend ( [ os . path . join ( path , subdir ) for subdir in subdirs ] ) | Generator of all files contained in media storage . | 94 | 10 |
245,339 | def _create_tar ( self , name ) : fileobj = utils . create_spooled_temporary_file ( ) mode = 'w:gz' if self . compress else 'w' tar_file = tarfile . open ( name = name , fileobj = fileobj , mode = mode ) for media_filename in self . _explore_storage ( ) : tarinfo = tarfile . TarInfo ( media_filename ) media_file = self... | Create TAR file . | 153 | 5 |
245,340 | def backup_mediafiles ( self ) : # Create file name extension = "tar%s" % ( '.gz' if self . compress else '' ) filename = utils . filename_generate ( extension , servername = self . servername , content_type = self . content_type ) tarball = self . _create_tar ( filename ) # Apply trans if self . encrypt : encrypted_fi... | Create backup file and write it to storage . | 181 | 9 |
245,341 | def bytes_to_str ( byteVal , decimals = 1 ) : for unit , byte in BYTES : if ( byteVal >= byte ) : if decimals == 0 : return '%s %s' % ( int ( round ( byteVal / byte , 0 ) ) , unit ) return '%s %s' % ( round ( byteVal / byte , decimals ) , unit ) return '%s B' % byteVal | Convert bytes to a human readable string . | 97 | 9 |
245,342 | def mail_admins ( subject , message , fail_silently = False , connection = None , html_message = None ) : if not settings . ADMINS : return mail = EmailMultiAlternatives ( '%s%s' % ( settings . EMAIL_SUBJECT_PREFIX , subject ) , message , settings . SERVER_EMAIL , [ a [ 1 ] for a in settings . ADMINS ] , connection = c... | Sends a message to the admins as defined by the DBBACKUP_ADMINS setting . | 134 | 21 |
245,343 | def create_spooled_temporary_file ( filepath = None , fileobj = None ) : spooled_file = tempfile . SpooledTemporaryFile ( max_size = settings . TMP_FILE_MAX_SIZE , dir = settings . TMP_DIR ) if filepath : fileobj = open ( filepath , 'r+b' ) if fileobj is not None : fileobj . seek ( 0 ) copyfileobj ( fileobj , spooled_f... | Create a spooled temporary file . if filepath or fileobj is defined its content will be copied into temporary file . | 125 | 25 |
245,344 | def compress_file ( inputfile , filename ) : outputfile = create_spooled_temporary_file ( ) new_filename = filename + '.gz' zipfile = gzip . GzipFile ( filename = filename , fileobj = outputfile , mode = "wb" ) try : inputfile . seek ( 0 ) copyfileobj ( inputfile , zipfile , settings . TMP_FILE_READ_SIZE ) finally : zi... | Compress input file using gzip and change its name . | 106 | 12 |
245,345 | def uncompress_file ( inputfile , filename ) : zipfile = gzip . GzipFile ( fileobj = inputfile , mode = "rb" ) try : outputfile = create_spooled_temporary_file ( fileobj = zipfile ) finally : zipfile . close ( ) new_basename = os . path . basename ( filename ) . replace ( '.gz' , '' ) return outputfile , new_basename | Uncompress this file using gzip and change its name . | 95 | 13 |
245,346 | def timestamp ( value ) : value = value if timezone . is_naive ( value ) else timezone . localtime ( value ) return value . strftime ( settings . DATE_FORMAT ) | Return the timestamp of a datetime . datetime object . | 43 | 12 |
245,347 | def datefmt_to_regex ( datefmt ) : new_string = datefmt for pat , reg in PATTERN_MATCHNG : new_string = new_string . replace ( pat , reg ) return re . compile ( r'(%s)' % new_string ) | Convert a strftime format string to a regex . | 64 | 11 |
245,348 | def filename_to_date ( filename , datefmt = None ) : datefmt = datefmt or settings . DATE_FORMAT datestring = filename_to_datestring ( filename , datefmt ) if datestring is not None : return datetime . strptime ( datestring , datefmt ) | Return a datetime from a file name . | 73 | 9 |
245,349 | def filename_generate ( extension , database_name = '' , servername = None , content_type = 'db' , wildcard = None ) : if content_type == 'db' : if '/' in database_name : database_name = os . path . basename ( database_name ) if '.' in database_name : database_name = database_name . split ( '.' ) [ 0 ] template = setti... | Create a new backup filename . | 281 | 6 |
245,350 | def get_storage ( path = None , options = None ) : path = path or settings . STORAGE options = options or settings . STORAGE_OPTIONS if not path : raise ImproperlyConfigured ( 'You must specify a storage class using ' 'DBBACKUP_STORAGE settings.' ) return Storage ( path , * * options ) | Get the specified storage configured with options . | 74 | 8 |
245,351 | def list_backups ( self , encrypted = None , compressed = None , content_type = None , database = None , servername = None ) : if content_type not in ( 'db' , 'media' , None ) : msg = "Bad content_type %s, must be 'db', 'media', or None" % ( content_type ) raise TypeError ( msg ) # TODO: Make better filter for include ... | List stored files except given filter . If filter is None it won t be used . content_type must be db for database backups or media for media backups . | 263 | 32 |
245,352 | def get_older_backup ( self , encrypted = None , compressed = None , content_type = None , database = None , servername = None ) : files = self . list_backups ( encrypted = encrypted , compressed = compressed , content_type = content_type , database = database , servername = servername ) if not files : raise FileNotFou... | Return the older backup s file name . | 106 | 8 |
245,353 | def clean_old_backups ( self , encrypted = None , compressed = None , content_type = None , database = None , servername = None , keep_number = None ) : if keep_number is None : keep_number = settings . CLEANUP_KEEP if content_type == 'db' else settings . CLEANUP_KEEP_MEDIA keep_filter = settings . CLEANUP_KEEP_FILTER ... | Delete olders backups and hold the number defined . | 204 | 10 |
245,354 | def _get_database ( self , options ) : database_name = options . get ( 'database' ) if not database_name : if len ( settings . DATABASES ) > 1 : errmsg = "Because this project contains more than one database, you" " must specify the --database option." raise CommandError ( errmsg ) database_name = list ( settings . DAT... | Get the database to restore . | 142 | 6 |
245,355 | def _restore_backup ( self ) : input_filename , input_file = self . _get_backup_file ( database = self . database_name , servername = self . servername ) self . logger . info ( "Restoring backup for database '%s' and server '%s'" , self . database_name , self . servername ) self . logger . info ( "Restoring: %s" % inpu... | Restore the specified database . | 275 | 6 |
245,356 | def get_connector ( database_name = None ) : from django . db import connections , DEFAULT_DB_ALIAS # Get DB database_name = database_name or DEFAULT_DB_ALIAS connection = connections [ database_name ] engine = connection . settings_dict [ 'ENGINE' ] connector_settings = settings . CONNECTORS . get ( database_name , { ... | Get a connector from its database key in setttings . | 192 | 12 |
245,357 | def settings ( self ) : if not hasattr ( self , '_settings' ) : sett = self . connection . settings_dict . copy ( ) sett . update ( settings . CONNECTORS . get ( self . database_name , { } ) ) self . _settings = sett return self . _settings | Mix of database and connector settings . | 65 | 7 |
245,358 | def run_command ( self , command , stdin = None , env = None ) : cmd = shlex . split ( command ) stdout = SpooledTemporaryFile ( max_size = settings . TMP_FILE_MAX_SIZE , dir = settings . TMP_DIR ) stderr = SpooledTemporaryFile ( max_size = settings . TMP_FILE_MAX_SIZE , dir = settings . TMP_DIR ) full_env = os . envir... | Launch a shell command line . | 359 | 6 |
245,359 | def _assign_zones ( self ) : for zone_id in range ( 1 , 5 ) : zone = RainCloudyFaucetZone ( parent = self . _parent , controller = self . _controller , faucet = self , zone_id = zone_id ) if zone not in self . zones : self . zones . append ( zone ) | Assign all RainCloudyFaucetZone managed by faucet . | 77 | 16 |
245,360 | def _find_zone_by_id ( self , zone_id ) : if not self . zones : return None zone = list ( filter ( lambda zone : zone . id == zone_id , self . zones ) ) return zone [ 0 ] if zone else None | Return zone by id . | 56 | 5 |
245,361 | def _set_zone_name ( self , zoneid , name ) : # zone starts with index 0 zoneid -= 1 data = { '_set_zone_name' : 'Set Name' , 'select_zone' : str ( zoneid ) , 'zone_name' : name , } self . _controller . post ( data ) | Private method to override zone name . | 73 | 7 |
245,362 | def _set_watering_time ( self , zoneid , value ) : if value not in MANUAL_WATERING_ALLOWED : raise ValueError ( 'Valid options are: {}' . format ( ', ' . join ( map ( str , MANUAL_WATERING_ALLOWED ) ) ) ) if isinstance ( value , int ) and value == 0 : value = 'OFF' elif isinstance ( value , str ) : value = value . uppe... | Private method to set watering_time per zone . | 169 | 10 |
245,363 | def watering_time ( self ) : # zone starts with index 0 index = self . id - 1 auto_watering_time = self . _attributes [ 'rain_delay_mode' ] [ index ] [ 'auto_watering_time' ] manual_watering_time = self . _attributes [ 'rain_delay_mode' ] [ index ] [ 'manual_watering_time' ] if auto_watering_time > manual_watering_time... | Return watering_time from zone . | 131 | 7 |
245,364 | def _set_rain_delay ( self , zoneid , value ) : # current index for rain_delay starts in 0 zoneid -= 1 if isinstance ( value , int ) : if value > MAX_RAIN_DELAY_DAYS or value < 0 : return None elif value == 0 : value = 'off' elif value == 1 : value = '1day' elif value >= 2 : value = str ( value ) + 'days' elif isinstan... | Generic method to set auto_watering program . | 170 | 10 |
245,365 | def _set_auto_watering ( self , zoneid , value ) : if not isinstance ( value , bool ) : return None ddata = self . preupdate ( ) attr = 'zone{}_program_toggle' . format ( zoneid ) try : if not value : ddata . pop ( attr ) else : ddata [ attr ] = 'on' except KeyError : pass self . submit_action ( ddata ) return True | Private method to set auto_watering program . | 98 | 10 |
245,366 | def auto_watering ( self ) : value = "zone{}" . format ( self . id ) return find_program_status ( self . _parent . html [ 'home' ] , value ) | Return if zone is configured to automatic watering . | 43 | 9 |
245,367 | def _to_dict ( self ) : return { 'auto_watering' : getattr ( self , "auto_watering" ) , 'droplet' : getattr ( self , "droplet" ) , 'is_watering' : getattr ( self , "is_watering" ) , 'name' : getattr ( self , "name" ) , 'next_cycle' : getattr ( self , "next_cycle" ) , 'rain_delay' : getattr ( self , "rain_delay" ) , 'wa... | Method to build zone dict . | 138 | 6 |
245,368 | def preupdate ( self , force_refresh = True ) : ddata = MANUAL_OP_DATA . copy ( ) # force update to make sure status is accurate if force_refresh : self . update ( ) # select current controller and faucet ddata [ 'select_controller' ] = self . _parent . controllers . index ( self . _controller ) ddata [ 'select_faucet'... | Return a dict with all current options prior submitting request . | 398 | 11 |
245,369 | def submit_action ( self , ddata ) : self . _controller . post ( ddata , url = HOME_ENDPOINT , referer = HOME_ENDPOINT ) | Post data . | 40 | 3 |
245,370 | def controller ( self ) : if hasattr ( self , 'controllers' ) : if len ( self . controllers ) > 1 : # in the future, we should support more controllers raise TypeError ( "Only one controller per account." ) return self . controllers [ 0 ] raise AttributeError ( "There is no controller assigned." ) | Show current linked controllers . | 70 | 5 |
245,371 | def _assign_faucets ( self , faucets ) : if not faucets : raise TypeError ( "Controller does not have a faucet assigned." ) for faucet_id in faucets : self . faucets . append ( RainCloudyFaucet ( self . _parent , self , faucet_id ) ) | Assign RainCloudyFaucet objects to self . faucets . | 78 | 16 |
245,372 | def post ( self , ddata , url = SETUP_ENDPOINT , referer = SETUP_ENDPOINT ) : headers = HEADERS . copy ( ) if referer is None : headers . pop ( 'Referer' ) else : headers [ 'Referer' ] = referer # append csrftoken if 'csrfmiddlewaretoken' not in ddata . keys ( ) : ddata [ 'csrfmiddlewaretoken' ] = self . _parent . csrf... | Method to update some attributes on namespace . | 145 | 8 |
245,373 | def _get_cu_and_fu_status ( self ) : # adjust headers headers = HEADERS . copy ( ) headers [ 'Accept' ] = '*/*' headers [ 'X-Requested-With' ] = 'XMLHttpRequest' headers [ 'X-CSRFToken' ] = self . _parent . csrftoken args = '?controller_serial=' + self . serial + '&faucet_serial=' + self . faucet . serial req = self . ... | Submit GET request to update information . | 190 | 7 |
245,374 | def name ( self , value ) : data = { '_set_controller_name' : 'Set Name' , 'controller_name' : value , } self . post ( data , url = SETUP_ENDPOINT , referer = SETUP_ENDPOINT ) | Set a new name to controller . | 61 | 7 |
245,375 | def faucet ( self ) : if hasattr ( self , 'faucets' ) : if len ( self . faucets ) > 1 : # in the future, we should support more faucets raise TypeError ( "Only one faucet per account." ) return self . faucets [ 0 ] raise AttributeError ( "There is no faucet assigned." ) | Show current linked faucet . | 83 | 7 |
245,376 | def serial_finder ( data ) : if not isinstance ( data , BeautifulSoup ) : raise TypeError ( "Function requires BeautifulSoup HTML element." ) try : # The setup page contains a select box for each controller and each # faucet controllersElement = data . find_all ( 'select' , { 'id' : 'id_select_controller2' } ) faucetsE... | Find controller serial and faucet_serial from the setup page . | 259 | 14 |
245,377 | def find_controller_or_faucet_name ( data , p_type ) : if not isinstance ( data , BeautifulSoup ) : raise TypeError ( "Function requires BeautilSoup HTML element." ) if not ( p_type == 'controller' or p_type == 'faucet' ) : raise TypeError ( "Function p_type must be controller or faucet" ) try : search_field = 'id_sele... | Find on the HTML document the controller name . | 147 | 9 |
245,378 | def find_zone_name ( data , zone_id ) : if not isinstance ( data , BeautifulSoup ) : raise TypeError ( "Function requires BeautilSoup HTML element." ) table = data . find ( 'table' , { 'class' : 'zone_table' } ) table_body = table . find ( 'tbody' ) rows = table_body . find_all ( 'span' , { 'class' : 'more_info' } ) fo... | Find on the HTML document the zone name . | 146 | 9 |
245,379 | def new_payment_query_listener ( sender , order = None , payment = None , * * kwargs ) : payment . amount = order . total payment . currency = order . currency logger . debug ( "new_payment_query_listener, amount=%s, currency=%s" , payment . amount , payment . currency ) | Here we fill only two obligatory fields of payment and leave signal handler | 74 | 13 |
245,380 | def payment_status_changed_listener ( sender , instance , old_status , new_status , * * kwargs ) : logger . debug ( "payment_status_changed_listener, old=%s, new=%s" , old_status , new_status ) if old_status != 'paid' and new_status == 'paid' : # Ensures that we process order only one instance . order . status = 'P' in... | Here we will actually do something when payment is accepted . E . g . lets change an order status . | 104 | 21 |
245,381 | def register_to_payment ( order_class , * * kwargs ) : global Payment global Order class Payment ( PaymentFactory . construct ( order = order_class , * * kwargs ) ) : objects = PaymentManager ( ) class Meta : ordering = ( '-created_on' , ) verbose_name = _ ( "Payment" ) verbose_name_plural = _ ( "Payments" ) Order = or... | A function for registering unaware order class to getpaid . This will generate a Payment model class that will store payments with ForeignKey to original order class | 167 | 29 |
245,382 | def get_backend_choices ( currency = None ) : choices = [ ] backends_names = getattr ( settings , 'GETPAID_BACKENDS' , [ ] ) for backend_name in backends_names : backend = import_module ( backend_name ) if currency : if currency in backend . PaymentProcessor . BACKEND_ACCEPTED_CURRENCY : choices . append ( ( backend_na... | Get active backends modules . Backend list can be filtered by supporting given currency . | 130 | 17 |
245,383 | def online ( cls , payload , ip , req_sig ) : from getpaid . models import Payment params = json . loads ( payload ) order_data = params . get ( 'order' , { } ) pos_id = order_data . get ( 'merchantPosId' ) payment_id = order_data . get ( 'extOrderId' ) key2 = cls . get_backend_setting ( 'key2' ) if pos_id != cls . get... | Receive and analyze request from payment service with information on payment status change . | 509 | 15 |
245,384 | def get_order_description ( self , payment , order ) : template = getattr ( settings , 'GETPAID_ORDER_DESCRIPTION' , None ) if template : return Template ( template ) . render ( Context ( { "payment" : payment , "order" : order } ) ) else : return six . text_type ( order ) | Renders order description using django template provided in settings . GETPAID_ORDER_DESCRIPTION or if not provided return unicode representation of Order object . | 74 | 33 |
245,385 | def get_backend_setting ( cls , name , default = None ) : backend_settings = get_backend_settings ( cls . BACKEND ) if default is not None : return backend_settings . get ( name , default ) else : try : return backend_settings [ name ] except KeyError : raise ImproperlyConfigured ( "getpaid '%s' requires backend '%s' s... | Reads name setting from backend settings dictionary . | 100 | 9 |
245,386 | def get_gateway_url ( self , request ) : params = { 'id' : self . get_backend_setting ( 'id' ) , 'description' : self . get_order_description ( self . payment , self . payment . order ) , 'amount' : self . payment . amount , 'currency' : self . payment . currency , 'type' : 0 , # 0 = show "return" button after finished... | Routes a payment to Gateway should return URL for redirection . | 658 | 14 |
245,387 | def channel_ready_future ( channel ) : fut = channel . _loop . create_future ( ) def _set_result ( state ) : if not fut . done ( ) and state is _grpc . ChannelConnectivity . READY : fut . set_result ( None ) fut . add_done_callback ( lambda f : channel . unsubscribe ( _set_result ) ) channel . subscribe ( _set_result ,... | Creates a Future that tracks when a Channel is ready . | 101 | 12 |
245,388 | def insecure_channel ( target , options = None , * , loop = None , executor = None , standalone_pool_for_streaming = False ) : return Channel ( _grpc . insecure_channel ( target , options ) , loop , executor , standalone_pool_for_streaming ) | Creates an insecure Channel to a server . | 64 | 9 |
245,389 | def secure_channel ( target , credentials , options = None , * , loop = None , executor = None , standalone_pool_for_streaming = False ) : return Channel ( _grpc . secure_channel ( target , credentials , options ) , loop , executor , standalone_pool_for_streaming ) | Creates a secure Channel to a server . | 68 | 9 |
245,390 | def future ( self , request , timeout = None , metadata = None , credentials = None ) : return _utils . wrap_future_call ( self . _inner . future ( request , timeout , metadata , credentials ) , self . _loop , self . _executor ) | Asynchronously invokes the underlying RPC . | 57 | 9 |
245,391 | async def with_call ( self , request_iterator , timeout = None , metadata = None , credentials = None ) : fut = self . future ( request_iterator , timeout , metadata , credentials ) try : result = await fut return ( result , fut ) finally : if not fut . done ( ) : fut . cancel ( ) | Synchronously invokes the underlying RPC on the client . | 69 | 12 |
245,392 | def future ( self , request_iterator , timeout = None , metadata = None , credentials = None ) : return _utils . wrap_future_call ( self . _inner . future ( _utils . WrappedAsyncIterator ( request_iterator , self . _loop ) , timeout , metadata , credentials ) , self . _loop , self . _executor ) | Asynchronously invokes the underlying RPC on the client . | 75 | 12 |
245,393 | def config_field_type ( field , cls ) : return defs . ConfigField ( lambda _ : isinstance ( _ , cls ) , lambda : CONFIG_FIELD_TYPE_ERROR . format ( field , cls . __name__ ) ) | Validate a config field against a type . | 54 | 9 |
245,394 | def get_config_parameters ( plugin_path ) : json_config_path = os . path . join ( plugin_path , defs . CONFIG_FILE_NAME ) with open ( json_config_path , "r" ) as f : config = json . load ( f ) return config . get ( defs . PARAMETERS , [ ] ) | Return the parameters section from config . json . | 78 | 9 |
245,395 | def validate_config_parameters ( config_json , allowed_keys , allowed_types ) : custom_fields = config_json . get ( defs . PARAMETERS , [ ] ) for field in custom_fields : validate_field ( field , allowed_keys , allowed_types ) default = field . get ( defs . DEFAULT ) field_type = field . get ( defs . TYPE ) if default ... | Validate parameters in config file . | 115 | 7 |
245,396 | def validate_field_matches_type ( field , value , field_type , select_items = None , _min = None , _max = None ) : if ( field_type == defs . TEXT_TYPE and not isinstance ( value , six . string_types ) ) or ( field_type == defs . STRING_TYPE and not isinstance ( value , six . string_types ) ) or ( field_type == defs . B... | Validate a config field against a specific type . | 322 | 10 |
245,397 | def get_truetype ( value ) : if value in [ "true" , "True" , "y" , "Y" , "yes" ] : return True if value in [ "false" , "False" , "n" , "N" , "no" ] : return False if value . isdigit ( ) : return int ( value ) return str ( value ) | Convert a string to a pythonized parameter . | 83 | 10 |
245,398 | def validate_field ( field , allowed_keys , allowed_types ) : for key , value in field . items ( ) : if key not in allowed_keys : raise exceptions . ParametersFieldError ( key , "property" ) if key == defs . TYPE : if value not in allowed_types : raise exceptions . ParametersFieldError ( value , key ) if key == defs . ... | Validate field is allowed and valid . | 111 | 8 |
245,399 | def is_valid_field_name ( value ) : leftovers = re . sub ( r"\w" , "" , value ) leftovers = re . sub ( r"-" , "" , leftovers ) if leftovers != "" or value [ 0 ] . isdigit ( ) or value [ 0 ] in [ "-" , "_" ] or " " in value : return False return True | Ensure field name is valid . | 83 | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.