Exemple #1
0
from pystemd.systemd1 import Unit
import time

unit_local = Unit(b'pulseaudio-linein-local.service')
unit_local.load()

unit_stream = Unit(b'pulseaudio-linein-stream.service')
unit_stream.load()

print(unit_local.ActiveState)
print(unit_stream.ActiveState)

if (unit_local.ActiveState == b'active'):
    print('Stopping local...')
    unit_local.Stop(b'replace')
    print('Starting stream...')
    unit_stream.Start(b'replace')
elif (unit_stream.ActiveState == b'active'):
    print('Stopping stream...')
    unit_stream.Stop(b'replace')
    print('Starting local...')
    unit_local.Start(b'replace')
else:
    unit_stream.Start(b'replace')

print(unit_local.ActiveState)
print(unit_stream.ActiveState)
Exemple #2
0
        import dnf

### install dev packages
try:
    from pystemd.systemd1 import Unit
except ImportError:
    if distro.name() == 'Fedora':
        system("dnf install python3-devel")
        system("dnf install systemd-libs")
        system("dnf install python3-pystemd")
        from pystemd.systemd1 import Unit

docker_service = Unit(b'docker.service')
docker_service.load()
if docker_service.ActiveState == b'inactive':
    docker_service.Start(b'docker.service')

### variavel global para usar o docker
client = docker.from_env()


### Gera o hash que será usado como senha no db
def HashGen():
    STAGING_KEY = "RANDOM"
    set_chars = string.ascii_letters + string.digits + string.punctuation
    STAGING_KEY = ''.join(
        [random.SystemRandom().choice(set_chars) for _ in range(128)])
    hash = hashlib.md5(STAGING_KEY.encode("UTF-8")).hexdigest()
    b64 = base64.b64encode(hash.encode('UTF-8'))
    b64str = b64.decode("UTF-8")
    dotenv.set_key(dotenv_file, "MONGODB_PASSWORD", b64str)