OpenSecurity/vm/usr/local/bin/new_firefox_profile_id.py
author om
Mon, 02 Dec 2013 16:02:00 +0100
changeset 5 166c38b8b6ed
permissions -rwxr-xr-x
added multiple session firefox script
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # new_firefox_profile_id
     6 # 
     7 # pick the next firefox profile id
     8 #
     9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    10 #
    11 # Copyright (C) 2013 AIT Austrian Institute of Technology
    12 # AIT Austrian Institute of Technology GmbH
    13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
    14 # http://www.ait.ac.at
    15 #
    16 # This program is free software; you can redistribute it and/or
    17 # modify it under the terms of the GNU General Public License
    18 # as published by the Free Software Foundation version 2.
    19 # 
    20 # This program is distributed in the hope that it will be useful,
    21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23 # GNU General Public License for more details.
    24 # 
    25 # You should have received a copy of the GNU General Public License
    26 # along with this program; if not, write to the Free Software
    27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    28 # Boston, MA  02110-1301, USA.
    29 # ------------------------------------------------------------
    30 
    31 
    32 # ------------------------------------------------------------
    33 # imports
    34 
    35 import os
    36 import os.path
    37 import ConfigParser     # in pythjon 3 this is lowercase
    38 
    39 
    40 # ------------------------------------------------------------
    41 # code
    42 
    43 
    44 def main():
    45 
    46     # grab the firefox profile ini (path may differ ...)
    47     profiles_path = os.path.join(os.path.expanduser('~'), '.mozilla', 'firefox', 'profiles.ini')
    48     cfg = ConfigParser.ConfigParser()
    49     cfg.read(profiles_path)
    50     profiles = [p for p in cfg.sections() if p.startswith('Profile')]
    51     i = 0
    52     for p in profiles:
    53         p_number = p[len('Profile'):]
    54         try:
    55             i = max(int(p_number), i)
    56         except:
    57             pass
    58     print i + 1
    59 
    60 
    61 if __name__ == '__main__':
    62     main()
    63 
    64