How to assign a priority number to “update-alternatives --config gdm3.css” in a single cmdline?Default folder to install customised GDM themeWhere does /etc/alternatives/gdm3.css pull its colors from?What is the correct url syntax for mytheme.css to access items in it's sub-directory?service lightdm modifing /etc/alternatives/x86_64-linux-gnu_gl_confI had changed Plymouth theme to text-only, but want it back in Graphical modeHow do I control all window shadows?How can I change the plymouth booting animation on Ubuntu 19.04?Default folder to install customised GDM themeInstalling customized GDM theme: Replacing ubuntu.css vs Using “update-alternatives --install … gdm3.css”
What happens when a photon "dies"?
5yrs old being bossy... Is this too much or tolerable at this age?
Approximation of homeomorphism by diffeomorphism
Understanding of big-O massively improved when I began thinking of orders as sets. How to apply the same approach to big-Theta?
What's the criteria/reasoning for Rick's three questions in The Walking Dead?
Is it ethical to apply for a short-term grant with a partner/spouse/girlfriend?
Why there is difference between performance of Vanguard S&P500 (VUSA) and S&P500 index
Were ancient languages as sophisticated as modern languages?
Solving inequality with logarithmic expression
Can you suck magic away from a wizard?
Why didn't classical music use drums?
Can a weapon be "unsheathable"?
Would it have been possible to re-fuel the planes in the air?
Why are the 4th and 7th scale degrees removed from the major scale to make the Pentatonic scale?
Tactical illusion combat countermeasures (password system)
Why is propagation delay a function of supply voltage?
How to appropriately quit a "bad" unpaid internship?
Is it advisable to cover and uncover the clarinet mouthpiece to play each note?
Texas gun laws - can an overseas visitor buy ammunition?
How to plot a uniform grid for a spatial and time domain using TikZ?
Can Toffoli operate on a qubit in superposition?
What game has this black main menu?
Why is the name 'propylene oxide' preferred for epoxypropane?
How Much Would a Language Change Over 500 Years Completely Cut Off From Its Source?
How to assign a priority number to “update-alternatives --config gdm3.css” in a single cmdline?
Default folder to install customised GDM themeWhere does /etc/alternatives/gdm3.css pull its colors from?What is the correct url syntax for mytheme.css to access items in it's sub-directory?service lightdm modifing /etc/alternatives/x86_64-linux-gnu_gl_confI had changed Plymouth theme to text-only, but want it back in Graphical modeHow do I control all window shadows?How can I change the plymouth booting animation on Ubuntu 19.04?Default folder to install customised GDM themeInstalling customized GDM theme: Replacing ubuntu.css vs Using “update-alternatives --install … gdm3.css”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am able to run these commands in the terminal:
$ sudo update-alternatives --install /usr/share/gnome-shell/theme/gdm3.css gdm3.css /usr/share/gnome-shell/theme/mytheme/mytheme.css 10
$ sudo update-alternatives --config gdm3.css
There are 2 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/share/gnome-shell/theme/ubuntu.css 10 auto mode
1 /usr/share/gnome-shell/theme/mytheme/mytheme.css 10 manual mode
2 /usr/share/gnome-shell/theme/ubuntu.css 10 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/share/gnome-shell/theme/mytheme/mytheme.css to provide /usr/share/gnome-shell/theme/gdm3.css (gdm3.css) in manual mode
I will put these two cmds in python3.6 subprocess.run().
The issue I have is with the second command. How do I assign /usr/share/gnome-shell/theme/mytheme/mytheme.css
to be the alternative of gdm3.css
in the same cmdline as sudo update-alternatives --config gdm3.css
?
Also, this cmd requires a number entry to select mytheme.css
. The assigned number is dependent on the assigned priority, which means the assigned number can be quite arbitrary. How do I overcome the arbitrary nature of the assigned number?
command-line gnome themes gdm update-alternatives
add a comment
|
I am able to run these commands in the terminal:
$ sudo update-alternatives --install /usr/share/gnome-shell/theme/gdm3.css gdm3.css /usr/share/gnome-shell/theme/mytheme/mytheme.css 10
$ sudo update-alternatives --config gdm3.css
There are 2 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/share/gnome-shell/theme/ubuntu.css 10 auto mode
1 /usr/share/gnome-shell/theme/mytheme/mytheme.css 10 manual mode
2 /usr/share/gnome-shell/theme/ubuntu.css 10 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/share/gnome-shell/theme/mytheme/mytheme.css to provide /usr/share/gnome-shell/theme/gdm3.css (gdm3.css) in manual mode
I will put these two cmds in python3.6 subprocess.run().
The issue I have is with the second command. How do I assign /usr/share/gnome-shell/theme/mytheme/mytheme.css
to be the alternative of gdm3.css
in the same cmdline as sudo update-alternatives --config gdm3.css
?
Also, this cmd requires a number entry to select mytheme.css
. The assigned number is dependent on the assigned priority, which means the assigned number can be quite arbitrary. How do I overcome the arbitrary nature of the assigned number?
command-line gnome themes gdm update-alternatives
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44
add a comment
|
I am able to run these commands in the terminal:
$ sudo update-alternatives --install /usr/share/gnome-shell/theme/gdm3.css gdm3.css /usr/share/gnome-shell/theme/mytheme/mytheme.css 10
$ sudo update-alternatives --config gdm3.css
There are 2 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/share/gnome-shell/theme/ubuntu.css 10 auto mode
1 /usr/share/gnome-shell/theme/mytheme/mytheme.css 10 manual mode
2 /usr/share/gnome-shell/theme/ubuntu.css 10 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/share/gnome-shell/theme/mytheme/mytheme.css to provide /usr/share/gnome-shell/theme/gdm3.css (gdm3.css) in manual mode
I will put these two cmds in python3.6 subprocess.run().
The issue I have is with the second command. How do I assign /usr/share/gnome-shell/theme/mytheme/mytheme.css
to be the alternative of gdm3.css
in the same cmdline as sudo update-alternatives --config gdm3.css
?
Also, this cmd requires a number entry to select mytheme.css
. The assigned number is dependent on the assigned priority, which means the assigned number can be quite arbitrary. How do I overcome the arbitrary nature of the assigned number?
command-line gnome themes gdm update-alternatives
I am able to run these commands in the terminal:
$ sudo update-alternatives --install /usr/share/gnome-shell/theme/gdm3.css gdm3.css /usr/share/gnome-shell/theme/mytheme/mytheme.css 10
$ sudo update-alternatives --config gdm3.css
There are 2 choices for the alternative gdm3.css (providing /usr/share/gnome-shell/theme/gdm3.css).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/share/gnome-shell/theme/ubuntu.css 10 auto mode
1 /usr/share/gnome-shell/theme/mytheme/mytheme.css 10 manual mode
2 /usr/share/gnome-shell/theme/ubuntu.css 10 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/share/gnome-shell/theme/mytheme/mytheme.css to provide /usr/share/gnome-shell/theme/gdm3.css (gdm3.css) in manual mode
I will put these two cmds in python3.6 subprocess.run().
The issue I have is with the second command. How do I assign /usr/share/gnome-shell/theme/mytheme/mytheme.css
to be the alternative of gdm3.css
in the same cmdline as sudo update-alternatives --config gdm3.css
?
Also, this cmd requires a number entry to select mytheme.css
. The assigned number is dependent on the assigned priority, which means the assigned number can be quite arbitrary. How do I overcome the arbitrary nature of the assigned number?
command-line gnome themes gdm update-alternatives
command-line gnome themes gdm update-alternatives
edited Oct 2 at 17:34
Sun Bear
asked Oct 2 at 17:08
Sun BearSun Bear
7486 silver badges20 bronze badges
7486 silver badges20 bronze badges
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44
add a comment
|
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44
add a comment
|
1 Answer
1
active
oldest
votes
Based on @PRATAP comment, I have developed this python3.6 solution to my question. It worked on my Ubuntu 18.04 system. I hope it can benefit others with the same need.
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
from subprocess import run, PIPE
from pathlib import Path
import mimetypes
class CSSFileTypeError(Exception):
pass
class GDM3_alternatives:
'''Class to query and configure gdm3.css.
Argument:
mytheme - path to my gnome-shell theme .css file.
Attributes:
mytheme - path to my gnome-shell theme .css file.
query - stdout from "update-alternatives --query gdm3.css" store in a list
link - gdm3.css path
best - gdm3.css alternative path selected by auto mode
value - current gdm3.css alternative path
status - whether gdm3.css is selected by manual or automatic mode
max - maximum Priority value of all the installed gdm3.css alternatives
Methods:
exist() - determines whether "mytheme" is installed as a gdm3.css alternative.
configure() - configure "mytheme" file as a gdm3.css alternative.
'''
def __init__( self, mytheme=None ):
def _get( qvalue ):
return [ line[ line.index('/') : ] for line in self.query if qvalue in line ][0]
self.mytheme = mytheme
self.query = run( [ 'update-alternatives', '--query', 'gdm3.css' ],
stdout=PIPE, encoding="utf-8" ).stdout.splitlines()
self.link = _get( 'Link:' )
self.best = _get( 'Best:' )
self.value = _get( 'Value:' )
self.status = [ line[ line.index(':')+2 : ] for line in self.query if 'Status:' in line ][0]
self.max = max( [ int( line[ line.index(':')+1 : ] ) for line in self.query if 'Priority:' in line ] )
#print( f'self.query = self.query' ) #For debugging
#print( f'self.link = self.link' ) #For debugging
#print( f'self.best = self.best' ) #For debugging
#print( f'self.value = self.value' ) #For debugging
#print( f'self.status= self.status' ) #For debugging
#print( f'self.max = self.max' ) #For debugging
def exist( self ):
'''Method that determines whether "mytheme.css" is installed as a gdm3.css alternative. '''
if self.mytheme == None:
raise TypeError( '.css file was not defined.' )
if not Path( self.mytheme ).exists():
raise FileNotFoundError( f'self.mytheme does not exist.' )
if 'css' not in mimetypes.guess_type( self.mytheme )[0] :
raise CSSFileTypeError( f'self.mytheme is not a css file.' )
return True in [ True for line in self.query if self.mytheme in line ]
def configure( self ):
'''Method to configure my theme ".css" file as a gdm3.css alternative.'''
def _config():
if 'auto' not in self.status:
run( [ 'update-alternatives', '--auto', 'gdm3.css' ] ) #Ensure auto mode is used
run( [ 'update-alternatives', '--install', self.link, 'gdm3.css', self.mytheme, str(self.max + 1) ] )
print( f'Configured self.mytheme as gdm3.css alternative.' )
if not self.exist():
_config()
elif self.value in self.mytheme:
print( f'self.mytheme is already gdm3.css alternative.' )
else:
run( [ 'update-alternatives', '--remove', 'gdm3.css', self.mytheme ] )
self.__init__( self.mytheme )
_config()
if __name__ == '__main__':
#mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css'
mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css' #Change this to your theme
gdm3 = GDM3_alternatives( mytheme )
gdm3.configure()
## This script needs to be executed by sudo. ##
How to use this script:
- Save it to a file with
.py
extension, e.g.myscript.py
. - Change line
mytheme =
to show your
'/usr/share/gnome-shell/theme/mytheme/mytheme.css'
theme's.css
path. - Run the script on terminal with sudo permission, i.e. type
sudo python3.6 myscript.py
. Or open your python IDLE usingsudo
permission and run this python script.
The version of the update-alternatives
on my Ubuntu 18.04 system is:
$ update-alternatives --version
Debian update-alternatives version 1.19.0.5.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1178169%2fhow-to-assign-a-priority-number-to-update-alternatives-config-gdm3-css-in-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Based on @PRATAP comment, I have developed this python3.6 solution to my question. It worked on my Ubuntu 18.04 system. I hope it can benefit others with the same need.
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
from subprocess import run, PIPE
from pathlib import Path
import mimetypes
class CSSFileTypeError(Exception):
pass
class GDM3_alternatives:
'''Class to query and configure gdm3.css.
Argument:
mytheme - path to my gnome-shell theme .css file.
Attributes:
mytheme - path to my gnome-shell theme .css file.
query - stdout from "update-alternatives --query gdm3.css" store in a list
link - gdm3.css path
best - gdm3.css alternative path selected by auto mode
value - current gdm3.css alternative path
status - whether gdm3.css is selected by manual or automatic mode
max - maximum Priority value of all the installed gdm3.css alternatives
Methods:
exist() - determines whether "mytheme" is installed as a gdm3.css alternative.
configure() - configure "mytheme" file as a gdm3.css alternative.
'''
def __init__( self, mytheme=None ):
def _get( qvalue ):
return [ line[ line.index('/') : ] for line in self.query if qvalue in line ][0]
self.mytheme = mytheme
self.query = run( [ 'update-alternatives', '--query', 'gdm3.css' ],
stdout=PIPE, encoding="utf-8" ).stdout.splitlines()
self.link = _get( 'Link:' )
self.best = _get( 'Best:' )
self.value = _get( 'Value:' )
self.status = [ line[ line.index(':')+2 : ] for line in self.query if 'Status:' in line ][0]
self.max = max( [ int( line[ line.index(':')+1 : ] ) for line in self.query if 'Priority:' in line ] )
#print( f'self.query = self.query' ) #For debugging
#print( f'self.link = self.link' ) #For debugging
#print( f'self.best = self.best' ) #For debugging
#print( f'self.value = self.value' ) #For debugging
#print( f'self.status= self.status' ) #For debugging
#print( f'self.max = self.max' ) #For debugging
def exist( self ):
'''Method that determines whether "mytheme.css" is installed as a gdm3.css alternative. '''
if self.mytheme == None:
raise TypeError( '.css file was not defined.' )
if not Path( self.mytheme ).exists():
raise FileNotFoundError( f'self.mytheme does not exist.' )
if 'css' not in mimetypes.guess_type( self.mytheme )[0] :
raise CSSFileTypeError( f'self.mytheme is not a css file.' )
return True in [ True for line in self.query if self.mytheme in line ]
def configure( self ):
'''Method to configure my theme ".css" file as a gdm3.css alternative.'''
def _config():
if 'auto' not in self.status:
run( [ 'update-alternatives', '--auto', 'gdm3.css' ] ) #Ensure auto mode is used
run( [ 'update-alternatives', '--install', self.link, 'gdm3.css', self.mytheme, str(self.max + 1) ] )
print( f'Configured self.mytheme as gdm3.css alternative.' )
if not self.exist():
_config()
elif self.value in self.mytheme:
print( f'self.mytheme is already gdm3.css alternative.' )
else:
run( [ 'update-alternatives', '--remove', 'gdm3.css', self.mytheme ] )
self.__init__( self.mytheme )
_config()
if __name__ == '__main__':
#mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css'
mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css' #Change this to your theme
gdm3 = GDM3_alternatives( mytheme )
gdm3.configure()
## This script needs to be executed by sudo. ##
How to use this script:
- Save it to a file with
.py
extension, e.g.myscript.py
. - Change line
mytheme =
to show your
'/usr/share/gnome-shell/theme/mytheme/mytheme.css'
theme's.css
path. - Run the script on terminal with sudo permission, i.e. type
sudo python3.6 myscript.py
. Or open your python IDLE usingsudo
permission and run this python script.
The version of the update-alternatives
on my Ubuntu 18.04 system is:
$ update-alternatives --version
Debian update-alternatives version 1.19.0.5.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
add a comment
|
Based on @PRATAP comment, I have developed this python3.6 solution to my question. It worked on my Ubuntu 18.04 system. I hope it can benefit others with the same need.
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
from subprocess import run, PIPE
from pathlib import Path
import mimetypes
class CSSFileTypeError(Exception):
pass
class GDM3_alternatives:
'''Class to query and configure gdm3.css.
Argument:
mytheme - path to my gnome-shell theme .css file.
Attributes:
mytheme - path to my gnome-shell theme .css file.
query - stdout from "update-alternatives --query gdm3.css" store in a list
link - gdm3.css path
best - gdm3.css alternative path selected by auto mode
value - current gdm3.css alternative path
status - whether gdm3.css is selected by manual or automatic mode
max - maximum Priority value of all the installed gdm3.css alternatives
Methods:
exist() - determines whether "mytheme" is installed as a gdm3.css alternative.
configure() - configure "mytheme" file as a gdm3.css alternative.
'''
def __init__( self, mytheme=None ):
def _get( qvalue ):
return [ line[ line.index('/') : ] for line in self.query if qvalue in line ][0]
self.mytheme = mytheme
self.query = run( [ 'update-alternatives', '--query', 'gdm3.css' ],
stdout=PIPE, encoding="utf-8" ).stdout.splitlines()
self.link = _get( 'Link:' )
self.best = _get( 'Best:' )
self.value = _get( 'Value:' )
self.status = [ line[ line.index(':')+2 : ] for line in self.query if 'Status:' in line ][0]
self.max = max( [ int( line[ line.index(':')+1 : ] ) for line in self.query if 'Priority:' in line ] )
#print( f'self.query = self.query' ) #For debugging
#print( f'self.link = self.link' ) #For debugging
#print( f'self.best = self.best' ) #For debugging
#print( f'self.value = self.value' ) #For debugging
#print( f'self.status= self.status' ) #For debugging
#print( f'self.max = self.max' ) #For debugging
def exist( self ):
'''Method that determines whether "mytheme.css" is installed as a gdm3.css alternative. '''
if self.mytheme == None:
raise TypeError( '.css file was not defined.' )
if not Path( self.mytheme ).exists():
raise FileNotFoundError( f'self.mytheme does not exist.' )
if 'css' not in mimetypes.guess_type( self.mytheme )[0] :
raise CSSFileTypeError( f'self.mytheme is not a css file.' )
return True in [ True for line in self.query if self.mytheme in line ]
def configure( self ):
'''Method to configure my theme ".css" file as a gdm3.css alternative.'''
def _config():
if 'auto' not in self.status:
run( [ 'update-alternatives', '--auto', 'gdm3.css' ] ) #Ensure auto mode is used
run( [ 'update-alternatives', '--install', self.link, 'gdm3.css', self.mytheme, str(self.max + 1) ] )
print( f'Configured self.mytheme as gdm3.css alternative.' )
if not self.exist():
_config()
elif self.value in self.mytheme:
print( f'self.mytheme is already gdm3.css alternative.' )
else:
run( [ 'update-alternatives', '--remove', 'gdm3.css', self.mytheme ] )
self.__init__( self.mytheme )
_config()
if __name__ == '__main__':
#mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css'
mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css' #Change this to your theme
gdm3 = GDM3_alternatives( mytheme )
gdm3.configure()
## This script needs to be executed by sudo. ##
How to use this script:
- Save it to a file with
.py
extension, e.g.myscript.py
. - Change line
mytheme =
to show your
'/usr/share/gnome-shell/theme/mytheme/mytheme.css'
theme's.css
path. - Run the script on terminal with sudo permission, i.e. type
sudo python3.6 myscript.py
. Or open your python IDLE usingsudo
permission and run this python script.
The version of the update-alternatives
on my Ubuntu 18.04 system is:
$ update-alternatives --version
Debian update-alternatives version 1.19.0.5.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
add a comment
|
Based on @PRATAP comment, I have developed this python3.6 solution to my question. It worked on my Ubuntu 18.04 system. I hope it can benefit others with the same need.
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
from subprocess import run, PIPE
from pathlib import Path
import mimetypes
class CSSFileTypeError(Exception):
pass
class GDM3_alternatives:
'''Class to query and configure gdm3.css.
Argument:
mytheme - path to my gnome-shell theme .css file.
Attributes:
mytheme - path to my gnome-shell theme .css file.
query - stdout from "update-alternatives --query gdm3.css" store in a list
link - gdm3.css path
best - gdm3.css alternative path selected by auto mode
value - current gdm3.css alternative path
status - whether gdm3.css is selected by manual or automatic mode
max - maximum Priority value of all the installed gdm3.css alternatives
Methods:
exist() - determines whether "mytheme" is installed as a gdm3.css alternative.
configure() - configure "mytheme" file as a gdm3.css alternative.
'''
def __init__( self, mytheme=None ):
def _get( qvalue ):
return [ line[ line.index('/') : ] for line in self.query if qvalue in line ][0]
self.mytheme = mytheme
self.query = run( [ 'update-alternatives', '--query', 'gdm3.css' ],
stdout=PIPE, encoding="utf-8" ).stdout.splitlines()
self.link = _get( 'Link:' )
self.best = _get( 'Best:' )
self.value = _get( 'Value:' )
self.status = [ line[ line.index(':')+2 : ] for line in self.query if 'Status:' in line ][0]
self.max = max( [ int( line[ line.index(':')+1 : ] ) for line in self.query if 'Priority:' in line ] )
#print( f'self.query = self.query' ) #For debugging
#print( f'self.link = self.link' ) #For debugging
#print( f'self.best = self.best' ) #For debugging
#print( f'self.value = self.value' ) #For debugging
#print( f'self.status= self.status' ) #For debugging
#print( f'self.max = self.max' ) #For debugging
def exist( self ):
'''Method that determines whether "mytheme.css" is installed as a gdm3.css alternative. '''
if self.mytheme == None:
raise TypeError( '.css file was not defined.' )
if not Path( self.mytheme ).exists():
raise FileNotFoundError( f'self.mytheme does not exist.' )
if 'css' not in mimetypes.guess_type( self.mytheme )[0] :
raise CSSFileTypeError( f'self.mytheme is not a css file.' )
return True in [ True for line in self.query if self.mytheme in line ]
def configure( self ):
'''Method to configure my theme ".css" file as a gdm3.css alternative.'''
def _config():
if 'auto' not in self.status:
run( [ 'update-alternatives', '--auto', 'gdm3.css' ] ) #Ensure auto mode is used
run( [ 'update-alternatives', '--install', self.link, 'gdm3.css', self.mytheme, str(self.max + 1) ] )
print( f'Configured self.mytheme as gdm3.css alternative.' )
if not self.exist():
_config()
elif self.value in self.mytheme:
print( f'self.mytheme is already gdm3.css alternative.' )
else:
run( [ 'update-alternatives', '--remove', 'gdm3.css', self.mytheme ] )
self.__init__( self.mytheme )
_config()
if __name__ == '__main__':
#mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css'
mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css' #Change this to your theme
gdm3 = GDM3_alternatives( mytheme )
gdm3.configure()
## This script needs to be executed by sudo. ##
How to use this script:
- Save it to a file with
.py
extension, e.g.myscript.py
. - Change line
mytheme =
to show your
'/usr/share/gnome-shell/theme/mytheme/mytheme.css'
theme's.css
path. - Run the script on terminal with sudo permission, i.e. type
sudo python3.6 myscript.py
. Or open your python IDLE usingsudo
permission and run this python script.
The version of the update-alternatives
on my Ubuntu 18.04 system is:
$ update-alternatives --version
Debian update-alternatives version 1.19.0.5.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
Based on @PRATAP comment, I have developed this python3.6 solution to my question. It worked on my Ubuntu 18.04 system. I hope it can benefit others with the same need.
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
from subprocess import run, PIPE
from pathlib import Path
import mimetypes
class CSSFileTypeError(Exception):
pass
class GDM3_alternatives:
'''Class to query and configure gdm3.css.
Argument:
mytheme - path to my gnome-shell theme .css file.
Attributes:
mytheme - path to my gnome-shell theme .css file.
query - stdout from "update-alternatives --query gdm3.css" store in a list
link - gdm3.css path
best - gdm3.css alternative path selected by auto mode
value - current gdm3.css alternative path
status - whether gdm3.css is selected by manual or automatic mode
max - maximum Priority value of all the installed gdm3.css alternatives
Methods:
exist() - determines whether "mytheme" is installed as a gdm3.css alternative.
configure() - configure "mytheme" file as a gdm3.css alternative.
'''
def __init__( self, mytheme=None ):
def _get( qvalue ):
return [ line[ line.index('/') : ] for line in self.query if qvalue in line ][0]
self.mytheme = mytheme
self.query = run( [ 'update-alternatives', '--query', 'gdm3.css' ],
stdout=PIPE, encoding="utf-8" ).stdout.splitlines()
self.link = _get( 'Link:' )
self.best = _get( 'Best:' )
self.value = _get( 'Value:' )
self.status = [ line[ line.index(':')+2 : ] for line in self.query if 'Status:' in line ][0]
self.max = max( [ int( line[ line.index(':')+1 : ] ) for line in self.query if 'Priority:' in line ] )
#print( f'self.query = self.query' ) #For debugging
#print( f'self.link = self.link' ) #For debugging
#print( f'self.best = self.best' ) #For debugging
#print( f'self.value = self.value' ) #For debugging
#print( f'self.status= self.status' ) #For debugging
#print( f'self.max = self.max' ) #For debugging
def exist( self ):
'''Method that determines whether "mytheme.css" is installed as a gdm3.css alternative. '''
if self.mytheme == None:
raise TypeError( '.css file was not defined.' )
if not Path( self.mytheme ).exists():
raise FileNotFoundError( f'self.mytheme does not exist.' )
if 'css' not in mimetypes.guess_type( self.mytheme )[0] :
raise CSSFileTypeError( f'self.mytheme is not a css file.' )
return True in [ True for line in self.query if self.mytheme in line ]
def configure( self ):
'''Method to configure my theme ".css" file as a gdm3.css alternative.'''
def _config():
if 'auto' not in self.status:
run( [ 'update-alternatives', '--auto', 'gdm3.css' ] ) #Ensure auto mode is used
run( [ 'update-alternatives', '--install', self.link, 'gdm3.css', self.mytheme, str(self.max + 1) ] )
print( f'Configured self.mytheme as gdm3.css alternative.' )
if not self.exist():
_config()
elif self.value in self.mytheme:
print( f'self.mytheme is already gdm3.css alternative.' )
else:
run( [ 'update-alternatives', '--remove', 'gdm3.css', self.mytheme ] )
self.__init__( self.mytheme )
_config()
if __name__ == '__main__':
#mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css'
mytheme = '/usr/share/gnome-shell/theme/mytheme/mytheme.css' #Change this to your theme
gdm3 = GDM3_alternatives( mytheme )
gdm3.configure()
## This script needs to be executed by sudo. ##
How to use this script:
- Save it to a file with
.py
extension, e.g.myscript.py
. - Change line
mytheme =
to show your
'/usr/share/gnome-shell/theme/mytheme/mytheme.css'
theme's.css
path. - Run the script on terminal with sudo permission, i.e. type
sudo python3.6 myscript.py
. Or open your python IDLE usingsudo
permission and run this python script.
The version of the update-alternatives
on my Ubuntu 18.04 system is:
$ update-alternatives --version
Debian update-alternatives version 1.19.0.5.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
edited Oct 4 at 13:45
answered Oct 3 at 14:42
Sun BearSun Bear
7486 silver badges20 bronze badges
7486 silver badges20 bronze badges
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
add a comment
|
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
@PRATAP I have improved on the python script. Use this one instead.
– Sun Bear
Oct 4 at 13:49
add a comment
|
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1178169%2fhow-to-assign-a-priority-number-to-update-alternatives-config-gdm3-css-in-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if you assign a priority higher than other alternatives.. then no need to add second command bcoz highest priority num will bcome the active..
– PRATAP
Oct 3 at 0:36
@PRATAP Thanks. :) I have shared my solution below. It uses the strategy that you had mentioned.
– Sun Bear
Oct 3 at 14:44