예제 #1
0
    def _check_hardlinks_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file1_path = os.path.join(tmp_path, 'file1')
        file2_path = os.path.join(tmp_path, 'file2')

        ret_val = False

        os.system("echo abc > \"%s\"" % file1_path)
        os.system("ln \"%s\" \"%s\"" % (file1_path, file2_path))
        os.system("echo abc > \"%s\"" % file2_path)

        if os.path.exists(file1_path) and os.path.exists(file2_path):
            try:
                info1 = os.stat(file1_path)
                info2 = os.stat(file2_path)

                if info1.st_size == info2.st_size:
                    ret_val = True
            except:
                pass

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #2
0
    def backupConfig(self):
        """
        create a backup of encfs config file into local config folder
        so in cases of the config file get deleted or corrupt user can restore
        it from there
        """
        cfg = self.configFile()
        if not os.path.isfile(cfg):
            logger.warning(
                'No encfs config in %s. Skip backup of config file.' % cfg,
                self)
            return
        backup_folder = self.config.encfsconfigBackupFolder(self.profile_id)
        tools.makeDirs(backup_folder)
        old_backups = os.listdir(backup_folder)
        old_backups.sort(reverse=True)
        if len(old_backups):
            last_backup = os.path.join(backup_folder, old_backups[0])

            #don't create a new backup if config hasn't changed
            if tools.md5sum(cfg) == \
               tools.md5sum(last_backup):
                logger.debug('Encfs config did not change. Skip backup', self)
                return

        new_backup_file = '.'.join(
            (os.path.basename(cfg), datetime.now().strftime('%Y%m%d%H%M')))
        new_backup = os.path.join(backup_folder, new_backup_file)
        logger.debug(
            'Create backup of encfs config %s to %s' % (cfg, new_backup), self)
        shutil.copy2(cfg, new_backup)
예제 #3
0
    def _check_hardlinks_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file1_path = os.path.join(tmp_path, 'file1')
        file2_path = os.path.join(tmp_path, 'file2')

        ret_val = False

        os.system("echo abc > \"%s\"" % file1_path)
        os.system("ln \"%s\" \"%s\"" % (file1_path, file2_path))
        os.system("echo abc > \"%s\"" % file2_path)

        if os.path.exists(file1_path) and os.path.exists(file2_path):
            try:
                info1 = os.stat(file1_path)
                info2 = os.stat(file2_path)

                if info1.st_size == info2.st_size:
                    ret_val = True
            except:
                pass

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #4
0
    def backupConfig(self):
        """
        create a backup of encfs config file into local config folder
        so in cases of the config file get deleted or corrupt user can restore
        it from there
        """
        cfg = self.configFile()
        if not os.path.isfile(cfg):
            logger.warning('No encfs config in %s. Skip backup of config file.' %cfg, self)
            return
        backup_folder = self.config.encfsconfigBackupFolder(self.profile_id)
        tools.makeDirs(backup_folder)
        old_backups = os.listdir(backup_folder)
        old_backups.sort(reverse = True)
        if len(old_backups):
            last_backup = os.path.join(backup_folder, old_backups[0])

            #don't create a new backup if config hasn't changed
            if tools.md5sum(cfg) == \
               tools.md5sum(last_backup):
                logger.debug('Encfs config did not change. Skip backup', self)
                return

        new_backup_file = '.'.join((os.path.basename(cfg), datetime.now().strftime('%Y%m%d%H%M')))
        new_backup = os.path.join(backup_folder, new_backup_file)
        logger.debug('Create backup of encfs config %s to %s'
                     %(cfg, new_backup), self)
        shutil.copy2(cfg, new_backup)
예제 #5
0
    def _check_usergroup_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file_path = os.path.join(tmp_path, 'file')
        os.system("echo abc > \"%s\"" % file_path)
        if not os.path.isfile(file_path):
            return False

        ret_val = False

        uid = os.getuid()
        gid = os.getgid()

        try:
            info = os.stat(file_path)
            if info.st_uid == uid and info.st_gid == gid:
                ret_val = True
        except:
            pass

        if ret_val and uid == 0:
            #try to change the group
            import grp

            #search for another group
            new_gid = gid
            new_name = ''
            for group in grp.getgrall():
                if group.gr_gid != gid:
                    new_gid = group.gr_gid
                    new_name = group.gr_name
                    break

            if new_gid != gid:
                os.system("chgrp %s \"%s\"" % (new_name, file_path))
                try:
                    info = os.stat(file_path)
                    if info.st_gid != new_gid:
                        ret_val = False
                except:
                    ret_val = False

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #6
0
    def _check_usergroup_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file_path = os.path.join(tmp_path, 'file')
        os.system("echo abc > \"%s\"" % file_path)
        if not os.path.isfile(file_path):
            return False

        ret_val = False

        uid = os.getuid()
        gid = os.getgid()

        try:
            info = os.stat(file_path)
            if info.st_uid == uid and info.st_gid == gid:
                ret_val = True
        except:
            pass

        if ret_val and uid == 0:
            #try to change the group
            import grp

            #search for another group
            new_gid = gid
            new_name = ''
            for group in grp.getgrall():
                if group.gr_gid != gid:
                    new_gid = group.gr_gid
                    new_name = group.gr_name
                    break

            if new_gid != gid:
                os.system("chgrp %s \"%s\"" % (new_name, file_path))
                try:
                    info = os.stat(file_path)
                    if info.st_gid != new_gid:
                        ret_val = False
                except:
                    ret_val = False

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #7
0
    def _check_perms_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file_path = os.path.join(tmp_path, 'file')
        os.system("echo abc > \"%s\"" % file_path)
        if not os.path.isfile(file_path):
            return False

        ret_val = False

        if self._check_perms_for_file_(file_path, '111'):
            if self._check_perms_for_file_(file_path, '700'):
                if self._check_perms_for_file_(file_path, '600'):
                    if self._check_perms_for_file_(file_path, '711'):
                        if self._check_perms_for_file_(file_path, '300'):
                            if self._check_perms_for_file_(file_path, '666'):
                                ret_val = True

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #8
0
    def _check_perms_(self):
        tmp_path = os.path.join(self.path, 'driveinfo.tmp')
        tools.makeDirs(tmp_path)
        if not os.path.isdir(tmp_path):
            return False

        file_path = os.path.join(tmp_path, 'file')
        os.system("echo abc > \"%s\"" % file_path)
        if not os.path.isfile(file_path):
            return False

        ret_val = False

        if self._check_perms_for_file_(file_path, '111'):
            if self._check_perms_for_file_(file_path, '700'):
                if self._check_perms_for_file_(file_path, '600'):
                    if self._check_perms_for_file_(file_path, '711'):
                        if self._check_perms_for_file_(file_path, '300'):
                            if self._check_perms_for_file_(file_path, '666'):
                                ret_val = True

        os.system("rm -rf \"%s\"" % tmp_path)
        return ret_val
예제 #9
0
 def test_makeDirs_not_writeable(self):
     with TemporaryDirectory() as d:
         os.chmod(d, stat.S_IRUSR)
         path = os.path.join(d,
                             'foobar{}'.format(random.randrange(100, 999)))
         self.assertFalse(tools.makeDirs(path))
예제 #10
0
 def test_makeDirs(self):
     self.assertFalse(tools.makeDirs('/'))
     self.assertTrue(tools.makeDirs(os.getcwd()))
     with TemporaryDirectory() as d:
         path = os.path.join(d, 'foo', 'bar')
         self.assertTrue(tools.makeDirs(path))
예제 #11
0
 values for each daemon individually.
 """
 APPCONF = Config(pathJoin(APPCONFPATH, APPNAME + '.conf'))
 # Read some settings to variables, set default values and update some values
 APPCONF['autostart'] = checkAutoStart(APPAUTOSTARTDST)
 # Setup on-screen notification settings from config value
 APPCONF.setdefault('notifications', True)
 APPCONF.setdefault('theme', False)
 APPCONF.setdefault('fmextensions', True)
 APPCONF.setdefault('daemons', '~/.config/yandex-disk/config.cfg')
 # Is it a first run?
 if not APPCONF.readSuccess:
     LOGGER.info('No config, probably it is a first run.')
     # Create application config folders in ~/.config
     try:
         makeDirs(APPCONFPATH)
         makeDirs(pathJoin(APPCONFPATH, 'icons/light'))
         makeDirs(pathJoin(APPCONFPATH, 'icons/dark'))
         # Copy icon themes readme to user config catalogue
         copyFile(pathJoin(APPINSTPATH, 'icons/readme'),
                  pathJoin(APPCONFPATH, 'icons/readme'))
     except:
         sysExit(_('Can\'t create configuration files in %s') % APPCONFPATH)
     # Activate indicator automatic start on system start-up
     if not pathExists(APPAUTOSTARTDST):
         try:
             makeDirs(expanduser('~/.config/autostart'))
             copyFile(APPAUTOSTARTSRC, APPAUTOSTARTDST)
             APPCONF['autostart'] = True
         except:
             LOGGER.error(
예제 #12
0
    asmText = addSection(asmText, sectionNumber)
    for entry in data:
        file = Path("data/" + entry["file"])
        size = file.stat().st_size
        if size >= sectionSizeLimit:
            print(file, "too big!", size)
            exit(1)
        # if spilling into next section, make new one
        if (bytesUsed + size) >= sectionSizeLimit:
            asmText = endSection(asmText)
            sectionNumber += 1
            asmText = addSection(asmText, sectionNumber)
            bytesUsed = 0
        bytesUsed += size
        name = entry["file"]
        label = entry["prefix"] + "_" + name.replace(".", "_")
        asmText += label + ":\n"
        asmText += '.incbin "data/' + name + '"\n'
        asmText += label + "_end:\n\n"
    asmText = endSection(asmText)

    open("data.asm", "w").write(asmText)


makeDirs()

data = []
processGraphics(data)
writeData(data)
writeHeader(data)
rotateScrollingBackgrounds()
예제 #13
0
 def test_makeDirs_not_writeable(self):
     with TemporaryDirectory() as d:
         os.chmod(d, stat.S_IRUSR)
         path = os.path.join(d, 'foobar{}'.format(random.randrange(100, 999)))
         self.assertFalse(tools.makeDirs(path))
예제 #14
0
 def test_makeDirs(self):
     self.assertFalse(tools.makeDirs('/'))
     self.assertTrue(tools.makeDirs(os.getcwd()))
     with TemporaryDirectory() as d:
         path = os.path.join(d, 'foo', 'bar')
         self.assertTrue(tools.makeDirs(path))