Exemplo n.º 1
0
def debug_log_dump_to_dated_file(config_filename):
    """Dumps the debug log to a unique file, convenient for reading by the user.

    @config_filename: See the documentation for debug_log_dump_as_list() to
    see how this argument is used.

    Return value: string with the name of the generated file."""

    t = time.localtime()

    basename = "sabayon-debug-log-%04d-%02d-%02d-%02d-%02d-%02d.txt" % (
        t.tm_year,
        t.tm_mon,
        t.tm_mday,
        t.tm_hour,
        t.tm_min,
        t.tm_sec,
    )

    name = os.path.join(util.get_home_dir(), basename)

    file = open(name, "w")
    debug_log_dump_to_file(config_filename, file)
    file.close()

    return name
Exemplo n.º 2
0
            def zip_directory (save_zip, dir, name):
                zip_filelist = save_zip.namelist()
                homedir = util.get_home_dir()

                for f in os.listdir (dir):
                    path = os.path.join (dir, f)
                    if os.path.isdir (path):
                        # We need to stop if we are recursing inside a ignored 
                        # directory.
                        if util.should_ignore_dir (homedir, 
                                DIRECTORIES_TO_IGNORE, os.path.join(homedir, name, f)):
                            dprint ("Not going inside %s as it is an ignored directory.", path)
                        else:
                            zip_directory (save_zip,
                                        path,
                                        os.path.join (name, f))
                    elif os.path.isfile (path):
                        # Avoid putting in a duplicate file entry
                        # See bug #476761
                        if os.path.join (name, f) in zip_filelist:
                            dprint ("Not adding %s to zipfile since it is already in the file", os.path.join (name, f))
                        elif util.should_ignore_file (homedir, 
                                DIRECTORIES_TO_IGNORE, FILES_TO_IGNORE, os.path.join(homedir, name, f)):
                            dprint ("Not adding %s to zipfile since it is a ignored file", os.path.join (name, f))
                        else:
                            zip_filelist.append(os.path.join(name, f))
                            save_zip.write (path, os.path.join (name, f))
Exemplo n.º 3
0
def run_unit_tests ():
    import gobject
    import tempfile

    real_homedir = util.get_home_dir ()
    
    temp_path = tempfile.mkdtemp (dir = real_homedir,
                                  prefix = ".test-filesprofile-")
    util.set_home_dir_for_unit_tests (temp_path)

    def handle_change (source, change, main_loop):
        source.commit_change (change)
        main_loop.quit ()

    main_loop = gobject.MainLoop ()
    
    def should_not_be_reached ():
        assert False
        return True
    timeout = gobject.timeout_add_seconds (60, should_not_be_reached)

    profile_path = os.path.join (os.getcwd (), "file-test.zip")
    if os.path.exists (profile_path):
        os.remove (profile_path)
    
    store = storage.ProfileStorage (profile_path)
    source = get_source (store)
    source.connect ("changed", handle_change, main_loop)
    source.start_monitoring ()

    os.makedirs (os.path.join (temp_path, "foobar/foo/bar/foo/bar"))
    
    f = file (os.path.join (temp_path, "foobar/foo/bar/foo/bar", "foo"), "w")
    f.close ()
    
    main_loop.run ()

    source.stop_monitoring ()

    store.save ()
    assert os.path.exists (profile_path)

    shutil.rmtree (temp_path, True)

    gobject.source_remove (timeout)

    temp_path = tempfile.mkdtemp (dir = real_homedir,
                                  prefix = ".test-filesprofile-")
    util.set_home_dir_for_unit_tests (temp_path)
    
    source = get_source (storage.ProfileStorage (profile_path))
    source.apply (False)
    
    assert os.access (os.path.join (temp_path, "foobar/foo/bar/foo/bar/foo"), os.F_OK)
    
    shutil.rmtree (temp_path, True)

    os.remove (profile_path)
    
    util.set_home_dir_for_unit_tests (None)
Exemplo n.º 4
0
    def write_installed_deps_file(self):
        if not len(self.installed_deps) > 0:
            return
        deps_file = open(os.path.join(get_home_dir(), ".eosio.install.deps"),
                         "wb")
        pickle.dump(self.installed_deps, deps_file)
        deps_file.close()
        os.chown(os.path.join(get_home_dir(), ".eosio.install.deps"),
                 get_original_uid()[0],
                 get_original_uid()[1])

        if is_owner_for_dir(get_file_dir()):
            deps_file = open(
                os.path.join(get_file_dir(), ".eosio.install.deps"), "wb")
            pickle.dump(self.installed_deps, deps_file)
            deps_file.close()
Exemplo n.º 5
0
    def __init__ (self, source):
        userprofile.SourceDelegate.__init__ (self, _("Panel"), source, PANEL_KEY_BASE)

        self.home_dir = util.get_home_dir()
        self.toplevels = {}
        self.applets = {}
        self.objects = {}
Exemplo n.º 6
0
 def __init__ (self, storage):
     userprofile.ProfileSource.__init__ (self, _("Files"), "get_files_delegate")
     self.storage = storage
     self.home_dir = util.get_home_dir ()
     self.monitor = dirmonitor.DirectoryMonitor (self.home_dir,
                                                 self.__handle_monitor_event)
     self.monitor.set_directories_to_ignore (DIRECTORIES_TO_IGNORE)
     self.monitor.set_files_to_ignore (FILES_TO_IGNORE)
Exemplo n.º 7
0
    def install(self, installed, dep, prefix):
        old_cwd = os.getcwd()
        tmpd = os.path.join(get_temp_dir(), dep.name)
        atexit.register(lambda: cleanup_tmp(tmpd))
        full_dir = os.path.join(tmpd, os.listdir(tmpd)[0], "build")
        os.chdir(full_dir)
        builder = str_to_class(dep.build_sys)()
        if not builder.install(installed, dep):
            err.log("Install stage for " + dep.name + " failed!")
        os.chdir(old_cwd)
        filenames = list()
        old_filenames = list()
        for path, subdirs, files in os.walk(tmpd + ".tmp"):
            for fn in files:
                full_path = os.path.join(path, fn)
                rel_path = os.path.relpath(full_path, tmpd + ".tmp")
                fixed_path = os.path.join(prefix, rel_path)
                filenames.append(fixed_path)
                old_filenames.append(full_path)

        ### for now ignore errors when making the prefix folder
        try:
            os.makedirs(prefix)
        except:
            pass
        ### check whether currently installed
        if self.check_install(prefix, filenames):
            err.log("Dependency " + dep.name +
                    " is already installed at location " + prefix)

        for i in range(0, len(filenames)):
            try:
                os.makedirs(os.path.dirname(filenames[i]))
            except:
                pass
            ### install to the prefix
            shutil.move(old_filenames[i], filenames[i])
        ### chown back to user if prefix is home rooted
        if os.path.commonprefix([get_home_dir(), filenames[i]]):
            os.chown(prefix, get_original_uid()[0], get_original_uid()[1])
            for root, dirs, files in os.walk(prefix):
                for d in dirs:
                    os.chown(os.path.join(root, d),
                             get_original_uid()[0],
                             get_original_uid()[1])
                for f in files:
                    os.chown(os.path.join(root, f),
                             get_original_uid()[0],
                             get_original_uid()[1])
        return installed_dependency(dep, True, prefix, filenames)
Exemplo n.º 8
0
    def __init__ (self, storage):
        """Construct a GConfSource

        @storage: storage object
        """
        userprofile.ProfileSource.__init__ (self, _("GConf"), "get_gconf_delegate")

        self.storage              = storage
        self.home_dir             = util.get_home_dir ()
        self.client               = None
        self.notify_id            = 0
        self.defaults_client      = None
        self.mandatory_client     = None
        self.mandatory_alt_client = None
        self.enforce_mandatory    = True
Exemplo n.º 9
0
    def read_installed_deps_file(self):
        try:
            deps_file = open(
                os.path.join(get_home_dir(), ".eosio.install.deps"), "rb")
            self.local_deps = pickle.load(deps_file)
            deps_file.close()
            self.installed_deps = self.local_deps.copy()

            if is_owner_for_dir(get_file_dir()):
                deps_file = open(
                    os.path.join(get_file_dir(), ".eosio.install.deps"), "rb")
                self.system_deps = pickle.load(deps_file)
                deps_file.close()
                self.installed_deps.update(self.system_deps)

        except Exception as Ex:
            pass
Exemplo n.º 10
0
def run_scons(variables=[]):
    packages_dir = os.path.join(util.get_home_dir(), 'packages')

    # Give the priority to the packages installed by apio
    os.environ['PATH'] = os.pathsep.join([
        os.path.join(packages_dir, 'toolchain-icestorm', 'bin'),
        os.environ['PATH']
    ])

    util.exec_command(
        [
            os.path.normpath(
                sys.executable),  # TODO: find python2 if executed with python3
            os.path.join(packages_dir, 'tool-scons', 'script', 'scons'),
            '-Q'
        ] + variables,
        stdout=util.AsyncPipe(on_run_out),
        stderr=util.AsyncPipe(on_run_err))
Exemplo n.º 11
0
 def make_labeltext(self):
     title = self._ostitle
     # FIXME title fiddling assumes standard linux PS1
     # pobably we oughta get cwd ourselves
     if not title:
         title = 'user@host:/some/path'
     pathpart = self.terminal.get_cwd()
     homepart = get_home_dir()
     if pathpart.startswith(homepart):
         # Tilde is barely noticeable with system font on high dpi displays.
         #pathpart = pathpart.replace(homepart,'<HOME>',1)
         pathpart = pathpart.replace(homepart, '⁓', 1)
     if self.titlefixed:
         if self._ctitle:
             self._autotext = ''
         elif self.config['title_hide_userhost']:
             self._autotext = '@'
         else:
             # user OR remote OR R@REMOTE
             self._autotext = "%s" % uhoextract(title, smart=True)
     elif self.config['title_hide_path'] \
         and self.config['title_hide_userhost']:
         self._autotext = r'.'
     elif self.config['title_hide_path']:
         self._autotext = "%s" % uhoextract(title)
     elif self.config['title_hide_userhost']:
         self._autotext = "%s" % pathpart
     else:
         self._autotext = "%s" % title
     # forcibly show at bar even if tabs are hidden
     if self.config['title_hide_tabcaption'] \
             and not self.config['tabs_hidden']:
         self._tabcapt = ''
     elif self.custom_caption:
         self._tabcapt = "[%s] " % self.custom_caption
     else:
         self._tabcapt = ''
     if self.config['title_hide_sizetext']:
         self._tsize = ''
     else:
         self._tsize = self.sizetext
Exemplo n.º 12
0
def get_home_dir():
    return util.get_home_dir()
Exemplo n.º 13
0
def run_unit_tests():
    main_loop = gobject.MainLoop()

    profile_path = os.path.join(os.getcwd(), "gconf-test.zip")
    if os.path.exists(profile_path):
        os.remove(profile_path)

    source = get_source(storage.ProfileStorage("GConfTest"))

    # Remove any stale path files
    try:
        os.remove(os.path.join(util.get_home_dir(), GCONF_PATH_DEFAULTS))
        os.remove(os.path.join(util.get_home_dir(), GCONF_PATH_MANDATORY))
    except:
        pass

    # Need to shutdown the daemon to ensure its not using stale paths
    subprocess.call(["gconftool-2", "--shutdown"])
    time.sleep(1)

    # Make sure there's no stale keys from a previous run
    # FIXME: gconf_client_recursive_unset() has no wrapping
    # source.gconf_client.recursive_unset ("/tmp/test-gconfprofile")
    subprocess.call(["gconftool-2", "--recursive-unset", "/tmp/test-gconfprofile"])
    time.sleep(1)

    global changes
    changes = []

    def handle_changed(source, change):
        global changes
        changes.append(change)

    source.connect("changed", handle_changed)

    source.start_monitoring()

    # Need to run the mainloop to get notifications.
    # The notification is only dispatched once the set
    # operation has complete
    # We poll after each set because otherwise GConfClient
    # will dispatch the two notifications for the same key
    def poll(main_loop):
        while main_loop.get_context().pending():
            main_loop.get_context().iteration(False)

    source.gconf_client.set_bool("/tmp/test-gconfprofile/t1", True)
    poll(main_loop)
    source.gconf_client.set_bool("/tmp/test-gconfprofile/t1", False)
    poll(main_loop)
    source.gconf_client.set_bool("/tmp/test-gconfprofile/t2", True)
    poll(main_loop)
    source.gconf_client.set_int("/tmp/test-gconfprofile/t3", 3)
    poll(main_loop)

    source.stop_monitoring()
    source.gconf_client = gconf.client_get_default()

    assert len(changes) == 4
    assert changes[3].key == "/tmp/test-gconfprofile/t3"
    source.commit_change(changes[3])

    assert changes[2].key == "/tmp/test-gconfprofile/t2"
    source.commit_change(changes[2], True)

    assert changes[1].key == "/tmp/test-gconfprofile/t1"
    assert changes[0].key == "/tmp/test-gconfprofile/t1"

    # source.gconf_client.recursive_unset ("/tmp/test-gconfprofile")
    subprocess.call(["gconftool-2", "--recursive-unset", "/tmp/test-gconfprofile"])

    source.sync_changes()
    source.apply(False)

    assert os.access(os.path.join(util.get_home_dir(), GCONF_PATH_DEFAULTS), os.F_OK)
    assert os.access(os.path.join(util.get_home_dir(), GCONF_PATH_MANDATORY), os.F_OK)

    # We need to clear the cache because GConfClient doesn't know
    # some new sources have been added to the sources stack so it
    # won't see the value we put in the mandatory source
    source.gconf_client.clear_cache()

    entry = source.gconf_client.get_entry("/tmp/test-gconfprofile/t3", "", False)
    assert entry.value
    assert entry.value.type == gconf.VALUE_INT
    assert entry.value.get_int() == 3
    assert not entry.get_is_default()
    assert entry.get_is_writable()

    entry = source.gconf_client.get_entry("/tmp/test-gconfprofile/t2", "", False)
    assert entry.value
    assert entry.value.type == gconf.VALUE_BOOL
    assert entry.value.get_bool() == True
    assert not entry.get_is_default()
    assert not entry.get_is_writable()

    # Shutdown the daemon and remove the path files so we don't screw
    # too much with the running session
    subprocess.call(["gconftool-2", "--shutdown"])
    time.sleep(1)

    os.remove(os.path.join(util.get_home_dir(), GCONF_PATH_DEFAULTS))
    os.remove(os.path.join(util.get_home_dir(), GCONF_PATH_MANDATORY))

    if os.path.exists(profile_path):
        os.remove(profile_path)
Exemplo n.º 14
0
class Installer(object):

    # Main packages dir
    profile = Profile()
    packages_dir = join(util.get_home_dir(), 'packages')

    def __init__(self):
        self.package = None

    def install(self):
        if self.package is not None:
            print('Install ' + self.package)
            if not isdir(self.packages_dir):
                makedirs(self.packages_dir)
            assert isdir(self.packages_dir)
            try:
                dlpath = None
                dlpath = self._download(self._get_download_url())
                if dlpath:
                    package_dir = join(self.packages_dir, self.package)
                    if isdir(package_dir):
                        shutil.rmtree(package_dir)
                    self._unpack(dlpath, self.packages_dir)
            except Exception:
                print('Package {0} is not found'.format(
                    self._get_package_name()))
            finally:
                if dlpath:
                    remove(dlpath)
                    self.profile.packages[self.package] = basename(dlpath)
                    self.profile.save()

    def uninstall(self):
        if self.package is not None:
            if isdir(join(self.packages_dir, self.package)):
                print('Uninstall package {0}'.format(self.package))
                shutil.rmtree(join(self.packages_dir, self.package))
            else:
                print('Package {0} is not installed'.format(self.package))
            self.profile.remove(self.package)
            self.profile.save()

    def _get_platform(self):
        return util.get_systype()

    def _get_download_url(self):
        raise NotImplementedError

    def _get_package_name(self):
        raise NotImplementedError

    def _download(self, url, sha1=None):
        fd = FileDownloader(url, self.packages_dir)
        if self.profile.check_version(self.package,
                                      basename(fd.get_filepath())):
            print('Download ' + basename(fd.get_filepath()))
            fd.start()
            fd.verify(sha1)
            return fd.get_filepath()
        else:
            print('Package {0} is already the newest version'.format(
                self.package))
            return None

    def _unpack(self, pkgpath, pkgdir):
        fu = FileUnpacker(pkgpath, pkgdir)
        return fu.start()
Exemplo n.º 15
0
 def _copy_tree (self, dir):
     if not self.gconf_client.dir_exists(dir):
         (src_client, src_address) = gconfsource.get_client_and_address_for_path (os.path.join (util.get_home_dir (), '.gconf'))
         (dst_client, dst_address) = gconfsource.get_client_and_address_for_path (os.path.join (util.get_home_dir (), GCONF_DEFAULTS_SOURCE))
         copy_dir (src_client, dst_client, dst_address, dir)