idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
60,200
def create ( self , template = None , flags = 0 , args = ( ) ) : if isinstance ( args , dict ) : template_args = [ ] for item in args . items ( ) : template_args . append ( "--%s" % item [ 0 ] ) template_args . append ( "%s" % item [ 1 ] ) else : template_args = args if template : return _lxc . Container . create ( self , template = template , flags = flags , args = tuple ( template_args ) ) else : return _lxc . Container . create ( self , flags = flags , args = tuple ( template_args ) )
Create a new rootfs for the container .
60,201
def clone ( self , newname , config_path = None , flags = 0 , bdevtype = None , bdevdata = None , newsize = 0 , hookargs = ( ) ) : args = { } args [ 'newname' ] = newname args [ 'flags' ] = flags args [ 'newsize' ] = newsize args [ 'hookargs' ] = hookargs if config_path : args [ 'config_path' ] = config_path if bdevtype : args [ 'bdevtype' ] = bdevtype if bdevdata : args [ 'bdevdata' ] = bdevdata if _lxc . Container . clone ( self , ** args ) : return Container ( newname , config_path = config_path ) else : return False
Clone the current container .
60,202
def get_cgroup_item ( self , key ) : value = _lxc . Container . get_cgroup_item ( self , key ) if value is False : return False else : return value . rstrip ( "\n" )
Returns the value for a given cgroup entry . A list is returned when multiple values are set .
60,203
def get_config_item ( self , key ) : value = _lxc . Container . get_config_item ( self , key ) if value is False : return False elif value . endswith ( "\n" ) : return value . rstrip ( "\n" ) . split ( "\n" ) else : return value
Returns the value for a given config key . A list is returned when multiple values are set .
60,204
def get_keys ( self , key = None ) : if key : value = _lxc . Container . get_keys ( self , key ) else : value = _lxc . Container . get_keys ( self ) if value is False : return False elif value . endswith ( "\n" ) : return value . rstrip ( "\n" ) . split ( "\n" ) else : return value
Returns a list of valid sub - keys .
60,205
def get_ips ( self , interface = None , family = None , scope = None , timeout = 0 ) : kwargs = { } if interface : kwargs [ 'interface' ] = interface if family : kwargs [ 'family' ] = family if scope : kwargs [ 'scope' ] = scope ips = None timeout = int ( os . environ . get ( 'LXC_GETIP_TIMEOUT' , timeout ) ) while not ips : ips = _lxc . Container . get_ips ( self , ** kwargs ) if timeout == 0 : break timeout -= 1 time . sleep ( 1 ) return ips
Get a tuple of IPs for the container .
60,206
def rename ( self , new_name ) : if _lxc . Container . rename ( self , new_name ) : return Container ( new_name ) return False
Rename the container . On success returns the new Container object . On failure returns False .
60,207
def set_config_item ( self , key , value ) : try : old_value = self . get_config_item ( key ) except KeyError : old_value = None if isinstance ( value , str ) : value = value . decode ( ) elif isinstance ( value , list ) : for i in range ( len ( value ) ) : if isinstance ( value [ i ] , str ) : value [ i ] = value [ i ] . decode ( ) def set_key ( key , value ) : self . clear_config_item ( key ) if isinstance ( value , list ) : for entry in value : if not _lxc . Container . set_config_item ( self , key , entry ) : return False else : _lxc . Container . set_config_item ( self , key , value ) set_key ( key , value ) new_value = self . get_config_item ( key ) if key == "lxc.loglevel" : new_value = value if ( isinstance ( value , unicode ) and isinstance ( new_value , unicode ) and value == new_value ) : return True elif ( isinstance ( value , list ) and isinstance ( new_value , list ) and set ( value ) == set ( new_value ) ) : return True elif ( isinstance ( value , unicode ) and isinstance ( new_value , list ) and set ( [ value ] ) == set ( new_value ) ) : return True elif old_value : set_key ( key , old_value ) return False else : self . clear_config_item ( key ) return False
Set a config key to a provided value . The value can be a list for the keys supporting multiple values .
60,208
def wait ( self , state , timeout = - 1 ) : if isinstance ( state , str ) : state = state . upper ( ) return _lxc . Container . wait ( self , state , timeout )
Wait for the container to reach a given state or timeout .
60,209
def render ( self , template , ** kwargs ) : try : temp = self . environment . get_template ( template ) return temp . render ( ** kwargs ) except AttributeError : err_msg = "Invalid value for 'template'" self . log . error ( err_msg ) raise exception . BadValue ( err_msg )
Renders the template
60,210
def listFields ( self , template ) : try : temp_source = self . environment . loader . get_source ( self . environment , template ) return self . listFieldsFromSource ( temp_source ) except AttributeError : err_msg = "Invalid value for 'template'" self . log . error ( err_msg ) raise exception . BadValue ( err_msg )
List all the attributes to be rendered from the template file
60,211
def listFieldsFromSource ( self , template_source ) : ast = self . environment . parse ( template_source ) return jinja2 . meta . find_undeclared_variables ( ast )
List all the attributes to be rendered directly from template source
60,212
def _get_file ( self ) : f = tempfile . NamedTemporaryFile ( delete = False ) self . tmp_files . add ( f . name ) return f
return an opened tempfile pointer that can be used
60,213
def _get_args ( self , executable , * args ) : args = list ( args ) args . insert ( 0 , executable ) if self . username : args . append ( "--username={}" . format ( self . username ) ) if self . host : args . append ( "--host={}" . format ( self . host ) ) if self . port : args . append ( "--port={}" . format ( self . port ) ) args . append ( self . dbname ) return args
compile all the executable and the arguments combining with common arguments to create a full batch of command args
60,214
def _get_outfile_path ( self , table ) : self . outfile_count += 1 outfile = os . path . join ( self . directory , '{:03d}_{}.sql.gz' . format ( self . outfile_count , table ) ) return outfile
return the path for a file we can use to back up the table
60,215
def _run_queries ( self , queries , * args , ** kwargs ) : f = self . _get_file ( ) for q in queries : f . write ( "{};\n" . format ( q ) ) f . close ( ) psql_args = self . _get_args ( 'psql' , '-X' , '-f {}' . format ( f . name ) ) return self . _run_cmd ( ' ' . join ( psql_args ) , * args , ** kwargs )
run the queries
60,216
def _restore_auto_increment ( self , table ) : query , seq_table , seq_column , seq_name = self . _get_auto_increment_info ( table ) if query : queries = [ query , "select nextval('{}')" . format ( seq_name ) ] return self . _run_queries ( queries )
restore the auto increment value for the table to what it was previously
60,217
def _get_auto_increment_info ( self , table ) : query = '' seq_table = '' seq_column = '' seq_name = '' find_query = "\n" . join ( [ "SELECT" , " t.relname as related_table," , " a.attname as related_column," , " s.relname as sequence_name" , "FROM pg_class s" , "JOIN pg_depend d ON d.objid = s.oid" , "JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid" , "JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)" , "JOIN pg_namespace n ON n.oid = s.relnamespace" , "WHERE" , " s.relkind = 'S'" , "AND" , " n.nspname = 'public'" , "AND" , " t.relname = '{}'" . format ( table ) ] ) pipe = self . _run_queries ( [ find_query ] , popen_kwargs = { 'stdout' : subprocess . PIPE } ) stdout , stderr = pipe . communicate ( ) if stdout : try : m = re . findall ( '^\s*(\S+)\s*\|\s*(\S+)\s*\|\s*(\S+)\s*$' , stdout , flags = re . MULTILINE ) seq_table , seq_column , seq_name = m [ 1 ] query = "\n" . join ( [ "SELECT" , " setval('{}'," . format ( seq_name . strip ( ) ) , " coalesce(max({}), 1)," . format ( seq_column . strip ( ) ) , " max({}) IS NOT null)" . format ( seq_column . strip ( ) ) , "FROM \"{}\"" . format ( seq_table . strip ( ) ) ] ) except IndexError : query = '' return query , seq_table , seq_column , seq_name
figure out the the autoincrement value for the given table
60,218
def restore ( self ) : sql_files = [ ] for root , dirs , files in os . walk ( self . directory ) : for f in files : if f . endswith ( ".sql.gz" ) : path = os . path . join ( self . directory , f ) self . _run_cmd ( [ "gunzip" , path ] ) sql_files . append ( f . rstrip ( ".gz" ) ) elif f . endswith ( '.sql' ) : sql_files . append ( f ) sql_files . sort ( ) r = re . compile ( '\d{3,}_([^\.]+)' ) for f in sql_files : path = os . path . join ( self . directory , f ) m = r . match ( f ) if m : table = m . group ( 1 ) logger . info ( '------- restoring table {}' . format ( table ) ) psql_args = self . _get_args ( 'psql' , '-X' , '--quiet' , '--file={}' . format ( path ) ) self . _run_cmd ( psql_args ) logger . info ( '------- restored table {}' . format ( table ) ) return True
use the self . directory to restore a db
60,219
def _get_env ( self ) : if hasattr ( self , 'env' ) : return self . env pgpass = self . _get_file ( ) pgpass . write ( '*:*:*:{}:{}\n' . format ( self . username , self . password ) . encode ( "utf-8" ) ) pgpass . close ( ) self . env = dict ( os . environ ) self . env [ 'PGPASSFILE' ] = pgpass . name if 'PGOPTIONS' in self . env : del self . env [ 'PGOPTIONS' ] return self . env
this returns an environment dictionary we want to use to run the command
60,220
def _get_response ( ** kwargs ) : if 'code' not in kwargs : kwargs [ 'code' ] = 200 if 'headers' not in kwargs : kwargs [ 'headers' ] = dict ( ) if 'version' not in kwargs : kwargs [ 'version' ] = 'HTTP/1.1' return dict ( ** kwargs )
Get a template response
60,221
def _write_transport ( self , string ) : if isinstance ( string , str ) : self . transport . write ( string . encode ( 'utf-8' ) ) else : self . transport . write ( string )
Convenience function to write to the transport
60,222
def _write_response ( self , response ) : status = '{} {} {}\r\n' . format ( response [ 'version' ] , response [ 'code' ] , responses [ response [ 'code' ] ] ) self . logger . debug ( "Responding status: '%s'" , status . strip ( ) ) self . _write_transport ( status ) if 'body' in response and 'Content-Length' not in response [ 'headers' ] : response [ 'headers' ] [ 'Content-Length' ] = len ( response [ 'body' ] ) response [ 'headers' ] [ 'Date' ] = datetime . utcnow ( ) . strftime ( "%a, %d %b %Y %H:%M:%S +0000" ) for ( header , content ) in response [ 'headers' ] . items ( ) : self . logger . debug ( "Sending header: '%s: %s'" , header , content ) self . _write_transport ( '{}: {}\r\n' . format ( header , content ) ) self . _write_transport ( '\r\n' ) if 'body' in response : self . _write_transport ( response [ 'body' ] )
Write the response back to the client
60,223
def connection_made ( self , transport ) : self . logger . info ( 'Connection made at object %s' , id ( self ) ) self . transport = transport self . keepalive = True if self . _timeout : self . logger . debug ( 'Registering timeout event' ) self . _timout_handle = self . _loop . call_later ( self . _timeout , self . _handle_timeout )
Called when the connection is made
60,224
def connection_lost ( self , exception ) : if exception : self . logger . exception ( 'Connection lost!' ) else : self . logger . info ( 'Connection lost' )
Called when the connection is lost or closed .
60,225
def data_received ( self , data ) : self . logger . debug ( 'Received data: %s' , repr ( data ) ) try : request = self . _parse_headers ( data ) self . _handle_request ( request ) except InvalidRequestError as e : self . _write_response ( e . get_http_response ( ) ) if not self . keepalive : if self . _timeout_handle : self . _timeout_handle . cancel ( ) self . transport . close ( ) if self . _timeout and self . _timeout_handle : self . logger . debug ( 'Delaying timeout event' ) self . _timeout_handle . cancel ( ) self . _timout_handle = self . _loop . call_later ( self . _timeout , self . _handle_timeout )
Process received data from the socket
60,226
def _get_request_uri ( self , request ) : request_uri = request [ 'target' ] if request_uri . startswith ( '/' ) : return ( request . get ( 'Host' , 'localhost' ) . split ( ':' ) [ 0 ] , request_uri [ 1 : ] ) elif '://' in request_uri : locator = request_uri . split ( '://' , 1 ) [ 1 ] host , path = locator . split ( '/' , 1 ) return ( host . split ( ':' ) [ 0 ] , path )
Parse the request URI into something useful
60,227
def _handle_request ( self , request ) : if request [ 'version' ] == 'HTTP/1.1' : self . keepalive = not request . get ( 'Connection' ) == 'close' elif request [ 'version' ] == 'HTTP/1.0' : self . keepalive = request . get ( 'Connection' ) == 'Keep-Alive' if request [ 'method' ] not in ( 'GET' ) : raise InvalidRequestError ( 501 , 'Method not implemented' ) if request [ 'version' ] not in ( 'HTTP/1.0' , 'HTTP/1.1' ) : raise InvalidRequestError ( 505 , 'Version not supported. Supported versions are: {}, {}' . format ( 'HTTP/1.0' , 'HTTP/1.1' ) ) host , location = self . _get_request_uri ( request ) if host is None : host = request . get ( 'Host' ) if host is not None and not host == self . host : self . logger . info ( 'Got a request for unknown host %s' , host ) raise InvalidRequestError ( 404 , "We don't serve this host" ) filename = os . path . join ( self . folder , unquote ( location ) ) self . logger . debug ( 'trying to serve %s' , filename ) if os . path . isdir ( filename ) : filename = os . path . join ( filename , 'index.html' ) if not os . path . isfile ( filename ) : raise InvalidRequestError ( 404 , 'Not Found' ) response = _get_response ( version = request [ 'version' ] ) match = re . match ( r'timeout=(\d+)' , request . get ( 'Keep-Alive' , '' ) ) if match is not None : requested_timeout = int ( match . group ( 1 ) ) if requested_timeout < self . _timeout : self . _timeout = requested_timeout if self . keepalive : response [ 'headers' ] [ 'Keep-Alive' ] = 'timeout={}' . format ( self . _timeout ) response [ 'headers' ] [ 'Content-Type' ] = mimetypes . guess_type ( filename ) [ 0 ] or 'text/plain' sha1 = hashlib . sha1 ( ) with open ( filename , 'rb' ) as fp : response [ 'body' ] = fp . read ( ) sha1 . update ( response [ 'body' ] ) etag = sha1 . hexdigest ( ) if request . get ( 'If-None-Match' ) == '"{}"' . format ( etag ) : response = _get_response ( code = 304 ) response [ 'headers' ] [ 'Etag' ] = '"{}"' . format ( etag ) self . _write_response ( response )
Process the headers and get the file
60,228
def get_http_response ( self ) : return _get_response ( code = self . code , body = str ( self ) , headers = { 'Content-Type' : 'text/plain' } )
Get this exception as an HTTP response suitable for output
60,229
def _start_server ( bindaddr , port , hostname , folder ) : import asyncio from . httpserver import HttpProtocol loop = asyncio . get_event_loop ( ) coroutine = loop . create_server ( lambda : HttpProtocol ( hostname , folder ) , bindaddr , port ) server = loop . run_until_complete ( coroutine ) print ( 'Starting server on {}' . format ( server . sockets [ 0 ] . getsockname ( ) ) ) try : loop . run_forever ( ) except KeyboardInterrupt : pass
Starts an asyncio server
60,230
def run ( argv = None ) : import sys import os import docopt import textwrap if not sys . version_info >= ( 3 , 4 ) : print ( 'This python version is not supported. Please use python 3.4' ) exit ( 1 ) argv = argv or sys . argv [ 1 : ] docblock = run . __doc__ . replace ( '::' , ':' ) args = docopt . docopt ( textwrap . dedent ( docblock ) , argv ) if args [ '--version' ] : print ( "httpserver version {} by {}" . format ( __version__ , __author__ ) ) exit ( 0 ) level = logging . WARNING if args [ '--verbose' ] : level = logging . INFO if args [ '--debug' ] : level = logging . DEBUG logging . basicConfig ( level = level ) logger = logging . getLogger ( 'run method' ) logger . debug ( 'CLI args: %s' % args ) bindaddr = args [ '--bindaddress' ] or '127.0.0.1' port = args [ '--port' ] or '8080' folder = args [ '<folder>' ] or os . getcwd ( ) hostname = args [ '--host' ] or 'localhost' _start_server ( bindaddr , port , hostname , folder )
Run the HTTP server
60,231
def reading ( self ) : try : proxies = { } try : proxies [ "http_proxy" ] = os . environ [ 'http_proxy' ] except KeyError : pass try : proxies [ "https_proxy" ] = os . environ [ 'https_proxy' ] except KeyError : pass if len ( proxies ) != 0 : proxy = urllib2 . ProxyHandler ( proxies ) opener = urllib2 . build_opener ( proxy ) urllib2 . install_opener ( opener ) f = urllib2 . urlopen ( self . link ) return f . read ( ) except ( urllib2 . URLError , ValueError ) : print ( "\n{0}Can't read the file '{1}'{2}" . format ( self . meta . color [ "RED" ] , self . link . split ( "/" ) [ - 1 ] , self . meta . color [ "ENDC" ] ) ) return " "
Open url and read
60,232
def repos ( self ) : def_cnt , cus_cnt = 0 , 0 print ( "" ) self . msg . template ( 78 ) print ( "{0}{1}{2}{3}{4}{5}{6}" . format ( "| Repo id" , " " * 2 , "Repo URL" , " " * 44 , "Default" , " " * 3 , "Status" ) ) self . msg . template ( 78 ) for repo_id , repo_URL in sorted ( self . all_repos . iteritems ( ) ) : status , COLOR = "disabled" , self . meta . color [ "RED" ] default = "yes" if len ( repo_URL ) > 49 : repo_URL = repo_URL [ : 48 ] + "~" if repo_id in self . meta . repositories : def_cnt += 1 status , COLOR = "enabled" , self . meta . color [ "GREEN" ] if repo_id not in self . meta . default_repositories : cus_cnt += 1 default = "no" print ( " {0}{1}{2}{3}{4}{5}{6}{7:>8}{8}" . format ( repo_id , " " * ( 9 - len ( repo_id ) ) , repo_URL , " " * ( 52 - len ( repo_URL ) ) , default , " " * ( 8 - len ( default ) ) , COLOR , status , self . meta . color [ "ENDC" ] ) ) print ( "\nRepositories summary" ) print ( "=" * 79 ) print ( "{0}{1}/{2} enabled default repositories and {3} custom." . format ( self . meta . color [ "GREY" ] , def_cnt , len ( self . all_repos ) , cus_cnt ) ) print ( "Edit the file '/etc/slpkg/repositories.conf' for enable " "and disable default\nrepositories or run 'slpkg " "repo-enable' command.\n{0}" . format ( self . meta . color [ "ENDC" ] ) ) raise SystemExit ( )
View or enabled or disabled repositories
60,233
def view ( self ) : print ( "" ) conf_args = [ "RELEASE" , "SLACKWARE_VERSION" , "COMP_ARCH" , "BUILD_PATH" , "PACKAGES" , "PATCHES" , "CHECKMD5" , "DEL_ALL" , "DEL_BUILD" , "SBO_BUILD_LOG" , "MAKEFLAGS" , "DEFAULT_ANSWER" , "REMOVE_DEPS_ANSWER" , "SKIP_UNST" , "RSL_DEPS" , "DEL_DEPS" , "USE_COLORS" , "DOWNDER" , "DOWNDER_OPTIONS" , "SLACKPKG_LOG" , "ONLY_INSTALLED" , "PRG_BAR" , "EDITOR" , "NOT_DOWNGRADE" ] read_conf = Utils ( ) . read_file ( self . config_file ) for line in read_conf . splitlines ( ) : if not line . startswith ( "#" ) and line . split ( "=" ) [ 0 ] in conf_args : print ( "{0}" . format ( line ) ) else : print ( "{0}{1}{2}" . format ( self . meta . color [ "CYAN" ] , line , self . meta . color [ "ENDC" ] ) ) print ( "" )
View slpkg config file
60,234
def edit ( self ) : subprocess . call ( "{0} {1}" . format ( self . meta . editor , self . config_file ) , shell = True )
Edit configuration file
60,235
def reset ( self ) : shutil . copy2 ( self . config_file + ".orig" , self . config_file ) if filecmp . cmp ( self . config_file + ".orig" , self . config_file ) : print ( "{0}The reset was done{1}" . format ( self . meta . color [ "GREEN" ] , self . meta . color [ "ENDC" ] ) ) else : print ( "{0}Reset failed{1}" . format ( self . meta . color [ "RED" ] , self . meta . color [ "ENDC" ] ) )
Reset slpkg . conf file with default values
60,236
def get ( self ) : if self . arch . startswith ( "i" ) and self . arch . endswith ( "86" ) : self . arch = self . x86 elif self . meta . arch . startswith ( "arm" ) : self . arch = self . arm return self . arch
Return sbo arch
60,237
def case_sensitive ( self , lst ) : dictionary = { } for pkg in lst : dictionary [ pkg . lower ( ) ] = pkg return dictionary
Create dictionary from list with key in lower case and value with default
60,238
def remove_dbs ( self , double ) : one = [ ] for dup in double : if dup not in one : one . append ( dup ) return one
Remove double item from list
60,239
def read_file ( self , registry ) : with open ( registry , "r" ) as file_txt : read_file = file_txt . read ( ) file_txt . close ( ) return read_file
Returns reading file
60,240
def package_name ( self , PACKAGES_TXT ) : packages = [ ] for line in PACKAGES_TXT . splitlines ( ) : if line . startswith ( "PACKAGE NAME:" ) : packages . append ( split_package ( line [ 14 : ] . strip ( ) ) [ 0 ] ) return packages
Returns list with all the names of packages repository
60,241
def check_downloaded ( self , path , maybe_downloaded ) : downloaded = [ ] for pkg in maybe_downloaded : if os . path . isfile ( path + pkg ) : downloaded . append ( pkg ) return downloaded
Check if files downloaded and return downloaded packages
60,242
def dependencies ( self , deps_dict ) : try : import pygraphviz as pgv except ImportError : graph_easy , comma = "" , "" if ( self . image == "ascii" and not os . path . isfile ( "/usr/bin/graph-easy" ) ) : comma = "," graph_easy = " graph-easy" print ( "Require 'pygraphviz{0}{1}': Install with 'slpkg -s sbo " "pygraphviz{1}'" . format ( comma , graph_easy ) ) raise SystemExit ( ) if self . image != "ascii" : self . check_file ( ) try : G = pgv . AGraph ( deps_dict ) G . layout ( prog = "fdp" ) if self . image == "ascii" : G . write ( "{0}.dot" . format ( self . image ) ) self . graph_easy ( ) G . draw ( self . image ) except IOError : raise SystemExit ( ) if os . path . isfile ( self . image ) : print ( "Graph image file '{0}' created" . format ( self . image ) ) raise SystemExit ( )
Generate graph file with depenndencies map tree
60,243
def check_file ( self ) : try : image_type = ".{0}" . format ( self . image . split ( "." ) [ 1 ] ) if image_type not in self . file_format : print ( "Format: '{0}' not recognized. Use one of " "them:\n{1}" . format ( self . image . split ( "." ) [ 1 ] , ", " . join ( self . file_format ) ) ) raise SystemExit ( ) except IndexError : print ( "slpkg: Error: Image file suffix missing" ) raise SystemExit ( )
Check for file format and type
60,244
def graph_easy ( self ) : if not os . path . isfile ( "/usr/bin/graph-easy" ) : print ( "Require 'graph-easy': Install with 'slpkg -s sbo " "graph-easy'" ) self . remove_dot ( ) raise SystemExit ( ) subprocess . call ( "graph-easy {0}.dot" . format ( self . image ) , shell = True ) self . remove_dot ( ) raise SystemExit ( )
Draw ascii diagram . graph - easy perl module require
60,245
def remove_dot ( self ) : if os . path . isfile ( "{0}.dot" . format ( self . image ) ) : os . remove ( "{0}.dot" . format ( self . image ) )
Remove . dot files
60,246
def alien_filter ( packages , sizes ) : cache , npkg , nsize = [ ] , [ ] , [ ] for p , s in zip ( packages , sizes ) : name = split_package ( p ) [ 0 ] if name not in cache : cache . append ( name ) npkg . append ( p ) nsize . append ( s ) return npkg , nsize
This filter avoid list double packages from alien repository
60,247
def upgrade ( self , flag ) : for pkg in self . binary : try : subprocess . call ( "upgradepkg {0} {1}" . format ( flag , pkg ) , shell = True ) check = pkg [ : - 4 ] . split ( "/" ) [ - 1 ] if os . path . isfile ( self . meta . pkg_path + check ) : print ( "Completed!\n" ) else : raise SystemExit ( ) except subprocess . CalledProcessError : self . _not_found ( "Can't upgrade" , self . binary , pkg ) raise SystemExit ( 1 )
Upgrade Slackware binary packages with new
60,248
def remove ( self , flag , extra ) : self . flag = flag self . extra = extra self . dep_path = self . meta . log_path + "dep/" dependencies , rmv_list = [ ] , [ ] self . removed = self . _view_removed ( ) if not self . removed : print ( "" ) else : msg = "package" if len ( self . removed ) > 1 : msg = msg + "s" try : if self . meta . default_answer in [ "y" , "Y" ] : remove_pkg = self . meta . default_answer else : remove_pkg = raw_input ( "\nAre you sure to remove {0} {1} [y/N]? " . format ( str ( len ( self . removed ) ) , msg ) ) except EOFError : print ( "" ) raise SystemExit ( ) if remove_pkg in [ "y" , "Y" ] : self . _check_if_used ( self . binary ) for rmv in self . removed : if ( os . path . isfile ( self . dep_path + rmv ) and self . meta . del_deps in [ "on" , "ON" ] or os . path . isfile ( self . dep_path + rmv ) and "--deps" in self . extra ) : dependencies = self . _view_deps ( self . dep_path , rmv ) if dependencies and self . _rmv_deps_answer ( ) in [ "y" , "Y" ] : rmv_list += self . _rmv_deps ( dependencies , rmv ) else : rmv_list += self . _rmv_pkg ( rmv ) else : rmv_list += self . _rmv_pkg ( rmv ) self . _reference_rmvs ( rmv_list )
Remove Slackware binary packages
60,249
def _rmv_deps_answer ( self ) : if self . meta . remove_deps_answer in [ "y" , "Y" ] : remove_dep = self . meta . remove_deps_answer else : try : remove_dep = raw_input ( "\nRemove dependencies (maybe used by " "other packages) [y/N]? " ) print ( "" ) except EOFError : print ( "" ) raise SystemExit ( ) return remove_dep
Remove dependencies answer
60,250
def _get_removed ( self ) : removed , packages = [ ] , [ ] if "--tag" in self . extra : for pkg in find_package ( "" , self . meta . pkg_path ) : for tag in self . binary : if pkg . endswith ( tag ) : removed . append ( split_package ( pkg ) [ 0 ] ) packages . append ( pkg ) if not removed : self . msg . pkg_not_found ( "" , "'tag'" , "Can't remove" , "\n" ) raise SystemExit ( 1 ) else : for pkg in self . binary : name = GetFromInstalled ( pkg ) . name ( ) ver = GetFromInstalled ( pkg ) . version ( ) package = find_package ( "{0}{1}{2}" . format ( name , ver , self . meta . sp ) , self . meta . pkg_path ) if pkg and name == pkg : removed . append ( pkg ) packages . append ( package [ 0 ] ) else : self . msg . pkg_not_found ( "" , pkg , "Can't remove" , "\n" ) raise SystemExit ( 1 ) return removed , packages
Manage removed packages by extra options
60,251
def _view_removed ( self ) : print ( "\nPackages with name matching [ {0}{1}{2} ]\n" . format ( self . meta . color [ "CYAN" ] , ", " . join ( self . binary ) , self . meta . color [ "ENDC" ] ) ) removed , packages = self . _get_removed ( ) if packages and "--checklist" in self . extra : removed = [ ] text = "Press 'spacebar' to unchoose packages from the remove" backtitle = "{0} {1}" . format ( self . meta . __all__ , self . meta . __version__ ) status = True pkgs = DialogUtil ( packages , text , " Remove " , backtitle , status ) . checklist ( ) if pkgs : for rmv in pkgs : removed . append ( split_package ( rmv ) [ 0 ] ) self . meta . default_answer = "y" else : for rmv , pkg in zip ( removed , packages ) : print ( "[ {0}delete{1} ] . format ( self . meta . color [ "RED" ] , self . meta . color [ "ENDC" ] , pkg ) ) self . _sizes ( pkg ) self . _calc_sizes ( ) self . _remove_summary ( ) return removed
View packages before removed
60,252
def _calc_sizes ( self ) : if self . size > 1024 : self . unit = "Mb" self . size = ( self . size / 1024 ) if self . size > 1024 : self . unit = "Gb" self . size = ( self . size / 1024 )
Package size calculation
60,253
def _remove_summary ( self ) : if self . size > 0 : print ( "\nRemoved summary" ) print ( "=" * 79 ) print ( "{0}Size of removed packages {1} {2}.{3}" . format ( self . meta . color [ "GREY" ] , round ( self . size , 2 ) , self . unit , self . meta . color [ "ENDC" ] ) )
Removed packge size summary
60,254
def _view_deps ( self , path , package ) : self . size = 0 packages = [ ] dependencies = ( Utils ( ) . read_file ( path + package ) ) . splitlines ( ) for dep in dependencies : if GetFromInstalled ( dep ) . name ( ) : ver = GetFromInstalled ( dep ) . version ( ) packages . append ( dep + ver ) else : dependencies . remove ( dep ) if packages : if "--checklist" in self . extra : deps , dependencies = [ ] , [ ] text = "Found dependencies for the package {0}" . format ( package ) backtitle = "{0} {1}" . format ( self . meta . __all__ , self . meta . __version__ ) status = True deps = DialogUtil ( packages , text , " Remove " , backtitle , status ) . checklist ( ) for d in deps : dependencies . append ( "-" . join ( d . split ( "-" ) [ : - 1 ] ) ) self . meta . remove_deps_answer = "y" else : print ( "" ) self . msg . template ( 78 ) print ( "| Found dependencies for the package {0}:" . format ( package ) ) self . msg . template ( 78 ) for pkg in packages : find = find_package ( pkg + self . meta . sp , self . meta . pkg_path ) self . _sizes ( find [ 0 ] ) print ( "| {0}{1}{2}" . format ( self . meta . color [ "RED" ] , pkg , self . meta . color [ "ENDC" ] ) ) self . msg . template ( 78 ) self . _calc_sizes ( ) print ( "| {0}Size of removed dependencies {1} {2}{3}" . format ( self . meta . color [ "GREY" ] , round ( self . size , 2 ) , self . unit , self . meta . color [ "ENDC" ] ) ) self . msg . template ( 78 ) return dependencies
View dependencies before remove
60,255
def _removepkg ( self , package ) : try : subprocess . call ( "removepkg {0} {1}" . format ( self . flag , package ) , shell = True ) if os . path . isfile ( self . dep_path + package ) : os . remove ( self . dep_path + package ) except subprocess . CalledProcessError as er : print ( er ) raise SystemExit ( )
removepkg Slackware command
60,256
def _rmv_pkg ( self , package ) : removes = [ ] if GetFromInstalled ( package ) . name ( ) and package not in self . skip : ver = GetFromInstalled ( package ) . version ( ) removes . append ( package + ver ) self . _removepkg ( package ) return removes
Remove one signle package
60,257
def _skip_remove ( self ) : if "--checklist" not in self . extra : self . msg . template ( 78 ) print ( "| Insert packages to exception remove:" ) self . msg . template ( 78 ) try : self . skip = raw_input ( " > " ) . split ( ) except EOFError : print ( "" ) raise SystemExit ( ) for s in self . skip : if s in self . removed : self . removed . remove ( s )
Skip packages from remove
60,258
def _check_if_used ( self , removes ) : if "--check-deps" in self . extra : package , dependency , pkg_dep = [ ] , [ ] , [ ] for pkg in find_package ( "" , self . dep_path ) : deps = Utils ( ) . read_file ( self . dep_path + pkg ) for rmv in removes : if GetFromInstalled ( rmv ) . name ( ) and rmv in deps . split ( ) : pkg_dep . append ( "{0} is dependency of the package . format ( rmv , pkg ) ) package . append ( pkg ) dependency . append ( rmv ) if package : if "--checklist" in self . extra : text = ( "Press 'spacebar' to choose packages for the remove" " exception" ) backtitle = "{0} {1}" . format ( self . meta . __all__ , self . meta . __version__ ) status = False choose = DialogUtil ( pkg_dep , text , " !!! WARNING !!! " , backtitle , status ) . checklist ( ) for pkg in choose : self . skip . append ( pkg . split ( ) [ 0 ] ) else : self . msg . template ( 78 ) print ( "| {0}{1}{2}" . format ( self . meta . color [ "RED" ] , " " * 30 + "!!! WARNING !!!" , self . meta . color [ "ENDC" ] ) ) self . msg . template ( 78 ) for p , d in zip ( package , dependency ) : print ( "| {0}{1}{2} is dependency of the package "{3}{4}{5}" . format ( self . meta . color [ "YELLOW" ] , d , self . meta . color [ "ENDC" ] , self . meta . color [ "GREEN" ] , p , self . meta . color [ "ENDC" ] ) ) self . msg . template ( 78 ) self . _skip_remove ( )
Check package if dependencies for another package before removed
60,259
def _reference_rmvs ( self , removes ) : print ( "" ) self . msg . template ( 78 ) msg_pkg = "package" if len ( removes ) > 1 : msg_pkg = "packages" print ( "| Total {0} {1} removed" . format ( len ( removes ) , msg_pkg ) ) self . msg . template ( 78 ) for pkg in removes : if not GetFromInstalled ( pkg ) . name ( ) : print ( "| Package {0} removed" . format ( pkg ) ) else : print ( "| Package {0} not found" . format ( pkg ) ) self . msg . template ( 78 ) print ( "" )
Prints all removed packages
60,260
def find ( self , flag ) : matching , pkg_cache , match_cache = 0 , "" , "" print ( "\nPackages with matching name [ {0}{1}{2} ]\n" . format ( self . meta . color [ "CYAN" ] , ", " . join ( self . binary ) , self . meta . color [ "ENDC" ] ) ) for pkg in self . binary : for match in find_package ( "" , self . meta . pkg_path ) : if "--case-ins" in flag : pkg_cache = pkg . lower ( ) match_cache = match . lower ( ) else : pkg_cache = pkg match_cache = match if pkg_cache in match_cache : matching += 1 self . _sizes ( match ) print ( "[ {0}installed{1} ] [ {2} ] - {3}" . format ( self . meta . color [ "GREEN" ] , self . meta . color [ "ENDC" ] , self . file_size , match ) ) if matching == 0 : message = "Can't find" self . msg . pkg_not_found ( "" , ", " . join ( self . binary ) , message , "\n" ) raise SystemExit ( 1 ) else : self . _calc_sizes ( ) print ( "\nFound summary" ) print ( "=" * 79 ) print ( "{0}Total found {1} matching packages.{2}" . format ( self . meta . color [ "GREY" ] , matching , self . meta . color [ "ENDC" ] ) ) print ( "{0}Size of installed packages {1} {2}.{3}\n" . format ( self . meta . color [ "GREY" ] , round ( self . size , 2 ) , self . unit , self . meta . color [ "ENDC" ] ) )
Find installed Slackware packages
60,261
def _sizes ( self , package ) : data = Utils ( ) . read_file ( self . meta . pkg_path + package ) for line in data . splitlines ( ) : if line . startswith ( "UNCOMPRESSED PACKAGE SIZE:" ) : digit = float ( ( '' . join ( re . findall ( "[-+]?\d+[\.]?\d*[eE]?[-+]?\d*" , line [ 26 : ] ) ) ) ) self . file_size = line [ 26 : ] . strip ( ) if "M" in line [ 26 : ] : self . size += digit * 1024 else : self . size += digit break
Package size summary
60,262
def display ( self ) : for pkg in self . binary : name = GetFromInstalled ( pkg ) . name ( ) ver = GetFromInstalled ( pkg ) . version ( ) find = find_package ( "{0}{1}{2}" . format ( name , ver , self . meta . sp ) , self . meta . pkg_path ) if find : package = Utils ( ) . read_file ( self . meta . pkg_path + "" . join ( find ) ) print ( package ) else : message = "Can't dislpay" if len ( self . binary ) > 1 : bol = eol = "" else : bol = eol = "\n" self . msg . pkg_not_found ( bol , pkg , message , eol ) raise SystemExit ( 1 )
Print the Slackware packages contents
60,263
def package_list ( self , repo , name , INDEX , installed ) : tty_size = os . popen ( "stty size" , "r" ) . read ( ) . split ( ) row = int ( tty_size [ 0 ] ) - 2 try : all_installed_names = [ ] index , page , pkg_list = 0 , row , [ ] r = self . list_lib ( repo ) pkg_list = self . list_greps ( repo , r ) [ 0 ] all_installed_names = self . list_of_installed ( repo , name ) print ( "" ) for pkg in sorted ( pkg_list ) : pkg = self . _splitting_packages ( pkg , repo , name ) if installed : if repo == "sbo" : if pkg in all_installed_names : pkg = ( "{0}{1}{2}" . format ( self . meta . color [ "GREEN" ] , pkg , self . meta . color [ "ENDC" ] ) ) else : if pkg in all_installed_names : pkg = ( "{0}{1}{2}" . format ( self . meta . color [ "GREEN" ] , pkg , self . meta . color [ "ENDC" ] ) ) if INDEX : index += 1 pkg = self . list_color_tag ( pkg ) print ( "{0}{1}:{2} {3}" . format ( self . meta . color [ "GREY" ] , index , self . meta . color [ "ENDC" ] , pkg ) ) if index == page : read = raw_input ( "\nPress {0}Enter{1} to " "continue... " . format ( self . meta . color [ "CYAN" ] , self . meta . color [ "ENDC" ] ) ) if read in [ "Q" , "q" ] : break print ( "" ) page += row else : print ( pkg ) print ( "" ) except EOFError : print ( "" ) raise SystemExit ( )
List with the installed packages
60,264
def _splitting_packages ( self , pkg , repo , name ) : if name and repo != "sbo" : pkg = split_package ( pkg ) [ 0 ] elif not name and repo != "sbo" : pkg = pkg [ : - 4 ] return pkg
Return package name from repositories
60,265
def list_lib ( self , repo ) : packages = "" if repo == "sbo" : if ( os . path . isfile ( self . meta . lib_path + "{0}_repo/SLACKBUILDS.TXT" . format ( repo ) ) ) : packages = Utils ( ) . read_file ( self . meta . lib_path + "{0}_repo/" "SLACKBUILDS.TXT" . format ( repo ) ) else : if ( os . path . isfile ( self . meta . lib_path + "{0}_repo/PACKAGES.TXT" . format ( repo ) ) ) : packages = Utils ( ) . read_file ( self . meta . lib_path + "{0}_repo/" "PACKAGES.TXT" . format ( repo ) ) return packages
Return package lists
60,266
def list_color_tag ( self , pkg ) : name = GetFromInstalled ( pkg ) . name ( ) find = name + self . meta . sp if pkg . endswith ( ".txz" ) or pkg . endswith ( ".tgz" ) : find = pkg [ : - 4 ] if find_package ( find , self . meta . pkg_path ) : pkg = "{0}{1}{2}" . format ( self . meta . color [ "GREEN" ] , pkg , self . meta . color [ "ENDC" ] ) return pkg
Tag with color installed packages
60,267
def list_of_installed ( self , repo , name ) : all_installed_names = [ ] all_installed_packages = find_package ( "" , self . meta . pkg_path ) for inst in all_installed_packages : if repo == "sbo" and inst . endswith ( "_SBo" ) : name = split_package ( inst ) [ 0 ] all_installed_names . append ( name ) else : if name : all_installed_names . append ( split_package ( inst ) [ 0 ] ) else : all_installed_names . append ( inst ) return all_installed_names
Return installed packages
60,268
def rlw_filter ( name , location , size , unsize ) : arch = _meta_ . arch if arch . startswith ( "i" ) and arch . endswith ( "86" ) : arch = "i486" ( fname , flocation , fsize , funsize ) = ( [ ] for i in range ( 4 ) ) for n , l , s , u in zip ( name , location , size , unsize ) : loc = l . split ( "/" ) if arch == loc [ - 1 ] : fname . append ( n ) flocation . append ( l ) fsize . append ( s ) funsize . append ( u ) return [ fname , flocation , fsize , funsize ]
Filter rlw repository data
60,269
def alien_filter ( name , location , size , unsize ) : ( fname , flocation , fsize , funsize ) = ( [ ] for i in range ( 4 ) ) for n , l , s , u in zip ( name , location , size , unsize ) : if "slackbuilds" != l : fname . append ( n ) flocation . append ( l ) fsize . append ( s ) funsize . append ( u ) return [ fname , flocation , fsize , funsize ]
Fix to avoid packages include in slackbuilds folder
60,270
def rested_filter ( name , location , size , unsize ) : ver = slack_ver ( ) if _meta_ . slack_rel == "current" : ver = "current" path_pkg = "pkg" if _meta_ . arch == "x86_64" : path_pkg = "pkg64" ( fname , flocation , fsize , funsize ) = ( [ ] for i in range ( 4 ) ) for n , l , s , u in zip ( name , location , size , unsize ) : if path_pkg == l . split ( "/" ) [ - 2 ] and ver == l . split ( "/" ) [ - 1 ] : fname . append ( n ) flocation . append ( l ) fsize . append ( s ) funsize . append ( u ) return [ fname , flocation , fsize , funsize ]
Filter Alien s repository data
60,271
def get_deps ( self ) : if self . repo == "rlw" : dependencies = { } rlw_deps = Utils ( ) . read_file ( _meta_ . conf_path + "rlworkman.deps" ) for line in rlw_deps . splitlines ( ) : if line and not line . startswith ( "#" ) : pkgs = line . split ( ":" ) dependencies [ pkgs [ 0 ] ] = pkgs [ 1 ] if self . name in dependencies . keys ( ) : return dependencies [ self . name ] . split ( ) else : return "" else : PACKAGES_TXT = Utils ( ) . read_file ( "{0}{1}_repo/PACKAGES.TXT" . format ( _meta_ . lib_path , self . repo ) ) for line in PACKAGES_TXT . splitlines ( ) : if line . startswith ( "PACKAGE NAME:" ) : pkg_name = split_package ( line [ 14 : ] . strip ( ) ) [ 0 ] if line . startswith ( "PACKAGE REQUIRED:" ) : if pkg_name == self . name : if line [ 18 : ] . strip ( ) : return self . _req_fix ( line )
Grap package requirements from repositories
60,272
def _req_fix ( self , line ) : deps = [ ] for dep in line [ 18 : ] . strip ( ) . split ( "," ) : dep = dep . split ( "|" ) if self . repo == "slacky" : if len ( dep ) > 1 : for d in dep : deps . append ( d . split ( ) [ 0 ] ) dep = "" . join ( dep ) deps . append ( dep . split ( ) [ 0 ] ) else : if len ( dep ) > 1 : for d in dep : deps . append ( d ) deps . append ( dep [ 0 ] ) return deps
Fix slacky and salix requirements because many dependencies splitting with and others with |
60,273
def run ( self ) : self . find_new ( ) for n in self . news : print ( "{0}" . format ( n ) ) print ( "" ) self . msg . template ( 78 ) print ( "| Installed {0} new configuration files:" . format ( len ( self . news ) ) ) self . msg . template ( 78 ) self . choices ( )
print . new configuration files
60,274
def choices ( self ) : print ( "| {0}K{1}{2}eep the old and .new files, no changes" . format ( self . red , self . endc , self . br ) ) print ( "| {0}O{1}{2}verwrite all old configuration files with new " "ones" . format ( self . red , self . endc , self . br ) ) print ( "| The old files will be saved with suffix .old" ) print ( "| {0}R{1}{2}emove all .new files" . format ( self . red , self . endc , self . br ) ) print ( "| {0}P{1}{2}rompt K, O, R, D, M option for each single " "file" . format ( self . red , self . endc , self . br ) ) print ( "| {0}Q{1}{2}uit from menu" . format ( self . red , self . endc , self . br ) ) self . msg . template ( 78 ) try : choose = raw_input ( "\nWhat would you like to do [K/O/R/P/Q]? " ) except EOFError : print ( "" ) raise SystemExit ( ) print ( "" ) if choose in ( "K" , "k" ) : self . keep ( ) elif choose in ( "O" , "o" ) : self . overwrite_all ( ) elif choose in ( "R" , "r" ) : self . remove_all ( ) elif choose in ( "P" , "p" ) : self . prompt ( )
Menu options for new configuration files
60,275
def question ( self , n ) : print ( "" ) prompt_ask = raw_input ( "{0} [K/O/R/D/M/Q]? " . format ( n ) ) print ( "" ) if prompt_ask in ( "K" , "k" ) : self . keep ( ) elif prompt_ask in ( "O" , "o" ) : self . _overwrite ( n ) elif prompt_ask in ( "R" , "r" ) : self . _remove ( n ) elif prompt_ask in ( "D" , "d" ) : self . diff ( n ) self . i -= 1 elif prompt_ask in ( "M" , "m" ) : self . merge ( n ) elif prompt_ask in ( "Q" , "q" , "quit" ) : self . quit ( )
Choose what do to file by file
60,276
def _remove ( self , n ) : if os . path . isfile ( n ) : os . remove ( n ) if not os . path . isfile ( n ) : print ( "File '{0}' removed" . format ( n ) )
Remove one single file
60,277
def _overwrite ( self , n ) : if os . path . isfile ( n [ : - 4 ] ) : shutil . copy2 ( n [ : - 4 ] , n [ : - 4 ] + ".old" ) print ( "Old file {0} saved as {1}.old" . format ( n [ : - 4 ] . split ( "/" ) [ - 1 ] , n [ : - 4 ] . split ( "/" ) [ - 1 ] ) ) if os . path . isfile ( n ) : shutil . move ( n , n [ : - 4 ] ) print ( "New file {0} overwrite as {1}" . format ( n . split ( "/" ) [ - 1 ] , n [ : - 4 ] . split ( "/" ) [ - 1 ] ) )
Overwrite old file with new and keep file with suffix . old
60,278
def diff ( self , n ) : if os . path . isfile ( n [ : - 4 ] ) : diff1 = Utils ( ) . read_file ( n [ : - 4 ] ) . splitlines ( ) if os . path . isfile ( n ) : diff2 = Utils ( ) . read_file ( n ) . splitlines ( ) lines , l , c = [ ] , 0 , 0 for a , b in itertools . izip_longest ( diff1 , diff2 ) : l += 1 if a != b : for s1 , s2 in itertools . izip_longest ( str ( a ) , str ( b ) ) : c += 1 if s1 != s2 : break print ( "@@ -{0},{1} +{2},{3} @@\n" . format ( l , c , l , c ) ) for line in lines [ - 3 : ] : print ( "{0}" . format ( line ) ) if a is None : a = "" print ( "{0}{1}{2}{3}" . format ( self . red , "-" , self . endc , a ) ) if b is None : b = "" print ( "{0}{1}{2}{3}" . format ( self . green , "+" , self . endc , b ) ) lines = [ ] c = 0 else : lines . append ( a )
Print the differences between the two files
60,279
def merge ( self , n ) : if os . path . isfile ( n [ : - 4 ] ) : old = Utils ( ) . read_file ( n [ : - 4 ] ) . splitlines ( ) if os . path . isfile ( n ) : new = Utils ( ) . read_file ( n ) . splitlines ( ) with open ( n [ : - 4 ] , "w" ) as out : for l1 , l2 in itertools . izip_longest ( old , new ) : if l1 is None : l1 = "" if l2 is None : l2 = "" if l1 != l2 : out . write ( l2 + "\n" ) else : out . write ( l1 + "\n" ) print ( "The file {0} merged in file {1}" . format ( n . split ( "/" ) [ - 1 ] , n [ : - 4 ] . split ( "/" ) [ - 1 ] ) )
Merge new file into old
60,280
def status_bar ( self ) : print ( "" ) self . msg . template ( 78 ) print ( "| Repository Status" ) self . msg . template ( 78 )
Top view bar status
60,281
def run ( self ) : if ( self . repo in self . meta . default_repositories and self . repo in self . meta . repositories ) : try : self . check = self . all_repos [ self . repo ] ( ) except OSError : usage ( self . repo ) raise SystemExit ( ) elif self . repo in self . meta . repositories : self . check = self . _init . custom ( self . repo ) else : usage ( self . repo ) raise SystemExit ( ) self . status_bar ( ) self . status ( ) self . print_status ( self . repo ) self . summary ( )
Run and check if new in ChangeLog . txt
60,282
def md5 ( source ) : source = source . replace ( "%2B" , "+" ) with open ( source ) as file_to_check : data = file_to_check . read ( ) return hashlib . md5 ( data ) . hexdigest ( )
Return MD5 Checksum
60,283
def run ( self ) : self . msg . resolving ( ) self . repositories ( ) if self . find_pkg : self . dependencies_list . reverse ( ) self . requires = Utils ( ) . dimensional_list ( self . dependencies_list ) self . dependencies = Utils ( ) . remove_dbs ( self . requires ) if self . dependencies == [ ] : self . dependencies = [ "No dependencies" ] if "--graph=" in self . flag : self . deps_tree ( ) self . msg . done ( ) pkg_len = len ( self . name ) + 24 print ( "" ) self . msg . template ( pkg_len ) print ( "| Package {0}{1}{2} dependencies :" . format ( self . cyan , self . name , self . endc ) ) self . msg . template ( pkg_len ) print ( "\\" ) print ( " +---{0}[ Tree of dependencies ]{1}" . format ( self . yellow , self . endc ) ) index = 0 for pkg in self . dependencies : if "--check-deps" in self . flag : used = self . check_used ( pkg ) self . deps_used ( pkg , used ) used = "{0} {1}{2}{3}" . format ( "is dependency , self . cyan , ", " . join ( used ) , self . endc ) else : used = "" index += 1 installed = "" if find_package ( pkg + self . meta . sp , self . meta . pkg_path ) : if self . meta . use_colors in [ "off" , "OFF" ] : installed = "* " print ( " |" ) print ( " {0}{1}: {2}{3}{4} {5}{6}" . format ( "+--" , index , self . green , pkg , self . endc , installed , used ) ) else : print ( " |" ) print ( " {0}{1}: {2}{3}{4} {5}" . format ( "+--" , index , self . red , pkg , self . endc , installed ) ) if self . meta . use_colors in [ "off" , "OFF" ] : print ( "\n * = Installed\n" ) else : print ( "" ) if "--graph=" in self . flag : self . graph ( ) else : self . msg . done ( ) print ( "\nNo package was found to match\n" ) raise SystemExit ( 1 )
Run tracking dependencies
60,284
def repositories ( self ) : if self . repo == "sbo" : self . sbo_case_insensitive ( ) self . find_pkg = sbo_search_pkg ( self . name ) if self . find_pkg : self . dependencies_list = Requires ( self . flag ) . sbo ( self . name ) else : PACKAGES_TXT = Utils ( ) . read_file ( self . meta . lib_path + "{0}_repo/PACKAGES.TXT" . format ( self . repo ) ) self . names = Utils ( ) . package_name ( PACKAGES_TXT ) self . bin_case_insensitive ( ) self . find_pkg = search_pkg ( self . name , self . repo ) if self . find_pkg : self . black = BlackList ( ) . packages ( self . names , self . repo ) self . dependencies_list = Dependencies ( self . repo , self . black ) . binary ( self . name , self . flag )
Get dependencies by repositories
60,285
def sbo_case_insensitive ( self ) : if "--case-ins" in self . flag : data = SBoGrep ( name = "" ) . names ( ) data_dict = Utils ( ) . case_sensitive ( data ) for key , value in data_dict . iteritems ( ) : if key == self . name . lower ( ) : self . name = value
Matching packages distinguish between uppercase and lowercase for sbo repository
60,286
def check_used ( self , pkg ) : used = [ ] dep_path = self . meta . log_path + "dep/" logs = find_package ( "" , dep_path ) for log in logs : deps = Utils ( ) . read_file ( dep_path + log ) for dep in deps . splitlines ( ) : if pkg == dep : used . append ( log ) return used
Check if dependencies used
60,287
def deps_tree ( self ) : dependencies = self . dependencies + [ self . name ] if self . repo == "sbo" : for dep in dependencies : deps = Requires ( flag = "" ) . sbo ( dep ) if dep not in self . deps_dict . values ( ) : self . deps_dict [ dep ] = Utils ( ) . dimensional_list ( deps ) else : for dep in dependencies : deps = Dependencies ( self . repo , self . black ) . binary ( dep , flag = "" ) if dep not in self . deps_dict . values ( ) : self . deps_dict [ dep ] = Utils ( ) . dimensional_list ( deps )
Package dependencies image map file
60,288
def deps_used ( self , pkg , used ) : if find_package ( pkg + self . meta . sp , self . meta . pkg_path ) : if pkg not in self . deps_dict . values ( ) : self . deps_dict [ pkg ] = used else : self . deps_dict [ pkg ] += used
Create dependencies dictionary
60,289
def version ( self ) : if self . find : return self . meta . sp + split_package ( self . find ) [ 1 ] return ""
Return version from installed packages
60,290
def it_self_update ( ) : __new_version__ = "" repository = "gitlab" branch = "master" ver_link = ( "https://raw.{0}usercontent.com/{1}/{2}/" "{3}/{4}/__metadata__.py" . format ( repository , _meta_ . __author__ , _meta_ . __all__ , branch , _meta_ . __all__ ) ) version_data = URL ( ver_link ) . reading ( ) for line in version_data . splitlines ( ) : line = line . strip ( ) if line . startswith ( "__version_info__" ) : __new_version__ = "." . join ( re . findall ( r"\d+" , line ) ) if __new_version__ > _meta_ . __version__ : if _meta_ . default_answer in [ "y" , "Y" ] : answer = _meta_ . default_answer else : print ( "\nNew version '{0}-{1}' is available !\n" . format ( _meta_ . __all__ , __new_version__ ) ) try : answer = raw_input ( "Would you like to upgrade [y/N]? " ) except EOFError : print ( "" ) raise SystemExit ( ) if answer in [ "y" , "Y" ] : print ( "" ) else : raise SystemExit ( ) dwn_link = [ "https://{0}.com/{1}/{2}/archive/" "v{3}/{4}-{5}.tar.gz" . format ( repository , _meta_ . __author__ , _meta_ . __all__ , __new_version__ , _meta_ . __all__ , __new_version__ ) ] if not os . path . exists ( _meta_ . build_path ) : os . makedirs ( _meta_ . build_path ) Download ( _meta_ . build_path , dwn_link , repo = "" ) . start ( ) os . chdir ( _meta_ . build_path ) slpkg_tar_file = "slpkg" + "-" + __new_version__ + ".tar.gz" tar = tarfile . open ( slpkg_tar_file ) tar . extractall ( ) tar . close ( ) file_name = "{0}-{1}" . format ( _meta_ . __all__ , __new_version__ ) os . chdir ( file_name ) check_md5 ( pkg_checksum ( slpkg_tar_file , _meta_ . __all__ ) , _meta_ . build_path + slpkg_tar_file ) subprocess . call ( "chmod +x {0}" . format ( "install.sh" ) , shell = True ) subprocess . call ( "sh install.sh" , shell = True ) else : print ( "\n{0}: There is no new version, already used the last !" "\n" . format ( _meta_ . __all__ ) ) raise SystemExit ( )
Check from GitHub slpkg repository if new version is available download and update itself
60,291
def if_all_installed ( self ) : count_inst = 0 for inst in ( self . dep_install + self . install ) : if ( os . path . isfile ( self . meta . pkg_path + inst [ : - 4 ] ) and "--download-only" not in self . flag ) : count_inst += 1 if ( count_inst == len ( self . dep_install + self . install ) and "--reinstall" not in self . flag ) : raise SystemExit ( )
Check if all packages is already installed
60,292
def clear_masters ( self ) : packages = [ ] for mas in Utils ( ) . remove_dbs ( self . packages ) : if mas not in self . dependencies : packages . append ( mas ) self . packages = packages
Clear master packages if already exist in dependencies or if added to install two or more times
60,293
def install_packages ( self ) : installs , upgraded = [ ] , [ ] for inst in ( self . dep_install + self . install ) : package = ( self . tmp_path + inst ) . split ( ) pkg_ver = "{0}-{1}" . format ( split_package ( inst ) [ 0 ] , split_package ( inst ) [ 1 ] ) self . checksums ( inst ) if GetFromInstalled ( split_package ( inst ) [ 0 ] ) . name ( ) : print ( "[ {0}upgrading{1} ] . format ( self . meta . color [ "YELLOW" ] , self . meta . color [ "ENDC" ] , inst ) ) upgraded . append ( pkg_ver ) if "--reinstall" in self . flag : PackageManager ( package ) . upgrade ( "--reinstall" ) else : PackageManager ( package ) . upgrade ( "--install-new" ) else : print ( "[ {0}installing{1} ] . format ( self . meta . color [ "GREEN" ] , self . meta . color [ "ENDC" ] , inst ) ) installs . append ( pkg_ver ) PackageManager ( package ) . upgrade ( "--install-new" ) return [ installs , upgraded ]
Install or upgrade packages
60,294
def not_downgrade ( self , package ) : name = split_package ( package ) [ 0 ] rep_ver = split_package ( package ) [ 1 ] ins_ver = GetFromInstalled ( name ) . version ( ) [ 1 : ] if not ins_ver : ins_ver = "0" if LooseVersion ( rep_ver ) < LooseVersion ( ins_ver ) : self . msg . template ( 78 ) print ( "| Package {0} don't downgrade, " "setting by user" . format ( name ) ) self . msg . template ( 78 ) return True
Don t downgrade packages if repository version is lower than installed
60,295
def checksums ( self , install ) : check_md5 ( pkg_checksum ( install , self . repo ) , self . tmp_path + install )
Checksums before install
60,296
def resolving_deps ( self ) : requires = [ ] if ( self . meta . rsl_deps in [ "on" , "ON" ] and self . flag != "--resolve-off" ) : self . msg . resolving ( ) for dep in self . packages : status ( 0.05 ) dependencies = [ ] dependencies = Utils ( ) . dimensional_list ( Dependencies ( self . repo , self . blacklist ) . binary ( dep , self . flag ) ) requires += self . _fix_deps_repos ( dependencies ) self . deps_dict [ dep ] = Utils ( ) . remove_dbs ( requires ) return Utils ( ) . remove_dbs ( requires )
Return package dependencies
60,297
def _fix_deps_repos ( self , dependencies ) : requires = [ ] for dep in dependencies : if dep in self . repo_pkg_names : requires . append ( dep ) return requires
Fix store deps include in repository
60,298
def top_view ( self ) : self . msg . template ( 78 ) print ( "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}" . format ( "| Package" , " " * 17 , "New Version" , " " * 8 , "Arch" , " " * 4 , "Build" , " " * 2 , "Repos" , " " * 10 , "Size" ) ) self . msg . template ( 78 )
Print packages status bar
60,299
def store ( self , packages ) : dwn , install , comp_sum , uncomp_sum = ( [ ] for i in range ( 4 ) ) for pkg in packages : for pk , loc , comp , uncomp in zip ( self . data [ 0 ] , self . data [ 1 ] , self . data [ 2 ] , self . data [ 3 ] ) : if ( pk and pkg == split_package ( pk ) [ 0 ] and pk not in install and split_package ( pk ) [ 0 ] not in self . blacklist ) : dwn . append ( "{0}{1}/{2}" . format ( self . mirror , loc , pk ) ) install . append ( pk ) comp_sum . append ( comp ) uncomp_sum . append ( uncomp ) if not install : for pkg in packages : for pk , loc , comp , uncomp in zip ( self . data [ 0 ] , self . data [ 1 ] , self . data [ 2 ] , self . data [ 3 ] ) : name = split_package ( pk ) [ 0 ] if ( pk and pkg in name and name not in self . blacklist ) : self . matching = True dwn . append ( "{0}{1}/{2}" . format ( self . mirror , loc , pk ) ) install . append ( pk ) comp_sum . append ( comp ) uncomp_sum . append ( uncomp ) dwn . reverse ( ) install . reverse ( ) comp_sum . reverse ( ) uncomp_sum . reverse ( ) if self . repo == "slack" : dwn , install , comp_sum , uncomp_sum = self . patches ( dwn , install , comp_sum , uncomp_sum ) return [ dwn , install , comp_sum , uncomp_sum ]
Store and return packages for install