Exemple #1
0
    def test_mediapath(self):
        """
        Test media path variables.
        """

        # Create database
        dbstate = DbState()
        db = dbstate.make_database("bsddb")
        path = get_empty_tempdir("utils_file_test")
        db.write_version(path)
        db.load(path)
        dbstate.change_database(db)

        # Test without db.mediapath set
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME))))
        self.assertTrue(os.path.exists(media_path(db)))

        # Test with absolute db.mediapath
        db.set_mediapath(os.path.abspath(USER_HOME) + "/test_abs")
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME + "/test_abs"))))

        # Test with relative db.mediapath
        db.set_mediapath("test_rel")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(TEMP_DIR + "/utils_file_test/test_rel")))
        )

        # Test with environment variable
        db.set_mediapath("/test/{VERSION}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath("/test/" + VERSION + "/test_var")))
        )
        db.set_mediapath("{USER_PLUGINS}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_PLUGINS + "/test_var")))
        )
        db.set_mediapath("{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(os.path.normpath(os.path.abspath(TEMP_DIR + "/utils_file_test/" + VERSION + "/test_var"))),
        )

        # Test with $GRAMPSHOME environment variable not set
        old_env = os.environ.copy()
        if "GRAMPSHOME" in os.environ:
            del os.environ["GRAMPSHOME"]
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(media_path(db), os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME + "/test_var"))))

        # Test with $GRAMPSHOME environment variable set
        os.environ["GRAMPSHOME"] = "/this/is/a/test"
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db), os.path.normcase(os.path.normpath(os.path.abspath("/this/is/a/test/test_var")))
        )

        #  Restore environment
        os.environ = old_env
Exemple #2
0
    def __import_action(self):
        """
        Take action for all given import files.

        .. note:: Family trees are not supported.

        If a family tree is open, the import happens on top of it. If not
        open, a new family tree is created, and the import done. If this
        is CLI, the created tree is deleted at the end (as some action will
        have happened that is now finished), if this is GUI, it is opened.
        """
        if self.imports:
            self.cl_bool = bool(self.exports or self.actions or self.cl_bool)

            if not self.open:
                # Create empty dir for imported database(s)
                if self.gui:
                    dbid = config.get('database.backend')
                    self.imp_db_path, title = self.dbman.create_new_db_cli(
                        dbid=dbid)
                else:
                    self.imp_db_path = get_empty_tempdir("import_dbdir")
                    dbid = config.get('database.backend')
                    newdb = make_database(dbid)
                    versionpath = os.path.join(self.imp_db_path,
                                               str(DBBACKEND))
                    with open(versionpath, "w") as version_file:
                        version_file.write(dbid)

                try:
                    self.smgr.open_activate(self.imp_db_path, self.username,
                                            self.password)
                    msg = _("Created empty Family Tree successfully")
                    print(msg, file=sys.stderr)
                except:
                    print(_("Error opening the file."), file=sys.stderr)
                    print(_("Exiting..."), file=sys.stderr)
                    sys.exit(1)

            for imp in self.imports:
                msg = _("Importing: file %(filename)s, format %(format)s.") % {
                    'filename': imp[0],
                    'format': imp[1]
                }
                print(msg, file=sys.stderr)
                self.cl_import(imp[0], imp[1])
Exemple #3
0
    def __import_action(self):
        """
        Take action for all given import files.

        .. note:: Family trees are not supported.

        If a family tree is open, the import happens on top of it. If not
        open, a new family tree is created, and the import done. If this
        is CLI, the created tree is deleted at the end (as some action will
        have happened that is now finished), if this is GUI, it is opened.
        """
        if self.imports:
            self.cl_bool = bool(self.exports or self.actions or self.cl_bool)

            if not self.open:
                # Create empty dir for imported database(s)
                if self.gui:
                    dbid = config.get('database.backend')
                    self.imp_db_path, title = self.dbman.create_new_db_cli(
                        dbid=dbid)
                else:
                    self.imp_db_path = get_empty_tempdir("import_dbdir")
                    dbid = config.get('database.backend')
                    newdb = self.dbstate.make_database(dbid)
                    newdb.write_version(self.imp_db_path)

                try:
                    self.smgr.open_activate(self.imp_db_path)
                    msg = _("Created empty Family Tree successfully")
                    print(msg, file=sys.stderr)
                except:
                    print(_("Error opening the file."), file=sys.stderr)
                    print(_("Exiting..."), file=sys.stderr)
                    sys.exit(1)

            for imp in self.imports:
                msg = _("Importing: file %(filename)s, format %(format)s."
                       ) % {'filename' : imp[0],
                            'format'   : imp[1]}
                print(msg, file=sys.stderr)
                self.cl_import(imp[0], imp[1])
Exemple #4
0
    def __import_action(self):
        """
        Take action for all given import files.
        
        .. note:: Family trees are not supported.

        If a family tree is open, the import happens on top of it. If not
        open, a new family tree is created, and the import done. If this
        is CLI, the created tree is deleted at the end (as some action will
        have happened that is now finished), if this is GUI, it is opened.
        """
        if self.imports:
            self.cl = bool(self.exports or self.actions or self.cl)

            if not self.open:
                # Create empty dir for imported database(s)
                if self.gui:
                    self.imp_db_path, title = self.dbman.create_new_db_cli()
                else:
                    self.imp_db_path = get_empty_tempdir("import_dbdir")
                    newdb = DbBsddb()
                    newdb.write_version(self.imp_db_path)

                try:
                    self.sm.open_activate(self.imp_db_path)
                    msg = _("Created empty Family Tree successfully")
                    print(msg, file=sys.stderr)
                except:
                    print(_("Error opening the file."), file=sys.stderr)
                    print(_("Exiting..."), file=sys.stderr)
                    sys.exit(0)

            for imp in self.imports:
                msg = _("Importing: file %(filename)s, format %(format)s.") % \
                        {'filename' : imp[0], 'format' : imp[1]}
                print(msg, file=sys.stderr)
                self.cl_import(imp[0], imp[1])
Exemple #5
0
        platform = "X11"
    elif win():
        platform = "Windows"
    elif mac():
        platform = "Macintosh"
    else:
        platform = "Unknown"
    lang = glocale.lang[:5].replace('_','-')
    return "Mozilla/5.0 (%s; U; %s) Gramps/3.2" % ( platform, lang)

#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
GEOVIEW_SUBPATH = get_empty_tempdir('geoview')
NOWEB   = 0
WEBKIT  = 1
MOZILLA = 2
KITNAME = [ "None", "WebKit", "Mozilla" ]
URL_SEP = '/'
MOZJS = '''
user_pref("network.proxy.type", 1);
user_pref("network.proxy.http", %(host)s);
user_pref("network.proxy.http_port", %(port)s);
user_pref("network.proxy.no_proxies_on",
 "127.0.0.1,localhost,localhost
 .localdomain")
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.http.proxy.pipelining", true);
user_pref("network.http.proxy.keep-alive", true);
Exemple #6
0
    elif win():
        platform = "Windows"
    elif mac():
        platform = "Macintosh"
    else:
        platform = "Unknown"
    lang = glocale.lang[:5].replace('_', '-')
    return "Mozilla/5.0 (%s; U; %s) Gramps/3.2" % (platform, lang)


#-------------------------------------------------------------------------
#
# Constants
#
#-------------------------------------------------------------------------
GEOVIEW_SUBPATH = get_empty_tempdir('geoview')
NOWEB = 0
WEBKIT = 1
MOZILLA = 2
KITNAME = ["None", "WebKit", "Mozilla"]
URL_SEP = '/'
MOZJS = '''
user_pref("network.proxy.type", 1);
user_pref("network.proxy.http", %(host)s);
user_pref("network.proxy.http_port", %(port)s);
user_pref("network.proxy.no_proxies_on",
 "127.0.0.1,localhost,localhost
 .localdomain")
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.http.proxy.pipelining", true);
user_pref("network.http.proxy.keep-alive", true);
Exemple #7
0
    def test_mediapath(self):
        """
        Test media path variables.
        """

        # Create database
        dbstate = DbState()
        db = dbstate.make_database("bsddb")
        path = get_empty_tempdir("utils_file_test")
        db.write_version(path)
        db.load(path)
        dbstate.change_database(db)

        # Test without db.mediapath set
        self.assertEqual(
            media_path(db),
            os.path.normcase(os.path.normpath(os.path.abspath(USER_HOME))))
        self.assertTrue(os.path.exists(media_path(db)))

        # Test with absolute db.mediapath
        db.set_mediapath(os.path.abspath(USER_HOME) + "/test_abs")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_HOME + "/test_abs"))))

        # Test with relative db.mediapath
        db.set_mediapath("test_rel")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath(TEMP_DIR + "/utils_file_test/test_rel"))))

        # Test with environment variable
        db.set_mediapath("/test/{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath("/test/" + VERSION + "/test_var"))))
        db.set_mediapath("{USER_PLUGINS}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_PLUGINS + "/test_var"))))
        db.set_mediapath("{VERSION}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(
                    os.path.abspath(TEMP_DIR + "/utils_file_test/" + VERSION +
                                    "/test_var"))))

        # Test with $GRAMPSHOME environment variable not set
        old_env = os.environ.copy()
        if 'GRAMPSHOME' in os.environ:
            del os.environ['GRAMPSHOME']
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath(USER_HOME + "/test_var"))))

        # Test with $GRAMPSHOME environment variable set
        os.environ['GRAMPSHOME'] = "/this/is/a/test"
        db.set_mediapath("{GRAMPSHOME}/test_var")
        self.assertEqual(
            media_path(db),
            os.path.normcase(
                os.path.normpath(os.path.abspath("/this/is/a/test/test_var"))))

        # Restore environment
        os.environ = old_env