Ejemplo n.º 1
0
 def get(self, local_file, remote_file):
     lf = FilePath(local_file)
     if lf.isfile():
         log.err("File already exists: %s" % local_file)
         defer.returnValue(1)
     rv = yield self._getRemoteFile(self.client, local_file, remote_file)
     defer.returnValue(rv)
Ejemplo n.º 2
0
Archivo: file.py Proyecto: hagna/mold
def inspect(doc):
    data = json.loads(doc)
    path = FilePath(data['path'])
    ret = {'kind': 'file', 'path': path.path, 'exists': path.exists()}
    if not ret['exists']:
        return ret
    
    if path.isdir():
        ret['filetype'] = 'dir'
    elif path.isfile():
        ret['filetype'] = 'file'
        ret['size'] = path.statinfo.st_size
        h = sha1()
        fh = open(path.path, 'r')
        while True:
            data = fh.read(4096)
            if not data:
                break
            h.update(data)
        ret['sha1'] = h.hexdigest()

    ret['owner'] = pwd.getpwuid(path.getUserID()).pw_name
    ret['group'] = grp.getgrgid(path.getGroupID()).gr_name
    ret['perms'] = permsString(path.getPermissions())
    ret['ctime'] = int(path.statinfo.st_ctime)
    ret['mtime'] = int(path.statinfo.st_mtime)
    ret['atime'] = int(path.statinfo.st_atime)
    return ret
Ejemplo n.º 3
0
 def put(self, local_file, remote_file):
     lf = FilePath(local_file)
     if not lf.isfile():
         log.err("Cannot find file: %s" % local_file)
         defer.returnValue(1)
     rv = yield self._putRemoteFile(self.client, local_file, remote_file)
     defer.returnValue(rv)
Ejemplo n.º 4
0
    def initConfig(self):
        try:
            configFile = self.get("configFile")

            if configFile is None:
                if FilePath("./.develop").isdir():
                    dev = FilePath("./conf/imsd.conf")
                    if dev.isfile():
                        configFile = dev

            if configFile is None:
                configuration = Configuration(None)
            else:
                if not configFile.isfile():
                    exit(ExitStatus.EX_CONFIG, "Config file not found.")
                configuration = Configuration(configFile)

            if "logFile" not in self:
                self.opt_log_file(configuration.LogFile)
            if "logFormat" not in self:
                self.opt_log_format(configuration.LogFormat)
            if "logLevel" not in self:
                self.opt_log_level(configuration.LogLevel)
            if "pidFile" not in self:
                self.opt_pid_file(configuration.PIDFile)

            self["configuration"] = configuration
        except Exception as e:
            exit(ExitStatus.EX_CONFIG, unicode(e))
Ejemplo n.º 5
0
def handle_config():
    if request.method == 'POST':    
        log.msg('Received JSON post with config')     
        jsonConfig = request.get_json(True)
        mumudvbConfig = ConfigParser.SafeConfigParser()
        for cardConfig in jsonConfig:
            card = cardConfig['_']['card']
            # Check the type, dvb-c = freq/1,000, dvb-s(2) = freq/1,000,000
            type = cardConfig['_']['type'] 
            if (type == 'DVB-C'):
                cardConfig['_']['freq'] =  int(cardConfig['_']['freq'])/1000
            else:
                cardConfig['_']['freq'] =  int(cardConfig['_']['freq'])/1000000
            # The DVB-S2 type needs an additional delivery system option
            if (type == 'DVB-S2'):
                cardConfig['_']['delivery_system'] = type
            cardConfig['_']['srate'] = int(cardConfig['_']['srate'])/1000
            cardConfig['_']['log_file'] = '/var/log/mumudvb' + card
            cardConfig['_']['log_type'] = 'syslog' 
            for section in sorted(cardConfig, reverse=True):                
                mumudvbConfig.add_section(section)
                for key in cardConfig[section]:
                    if (cardConfig[section][key] != None and key != 'type'):
                            mumudvbConfig.set(section,str(key),str(cardConfig[section][key]))                            
            cardConf = FilePath(tmpdir.path+'/dvbrc_adapter' + card + '.conf')
            with FilePath.open(cardConf, 'wb') as configfile:   
                mumudvbConfig.write(configfile)
            if FilePath.isfile(cardConf):
                mumu = startMumudvb(card)
                cmd = ["mumudvb","-d","-c", cardConf.path]
                log.msg('Starting MuMuDVB with the following flags: ' + str(cmd) + ' on card ' + card)
                process = reactor.spawnProcess(mumu, cmd[0], cmd, usePTY=True, env=None)
                log.msg(process)
    return ''
Ejemplo n.º 6
0
 def stop_pipeline(self):
     self.pipeline.set_state(Gst.State.READY)
     plfile = FilePath("playlist.m3u8")
     segments = FilePath("./").globChildren("segment*")
     for segment in segments:
         segment.remove()
     if plfile.exists() and plfile.isfile():
         plfile.remove()
Ejemplo n.º 7
0
 def getPrivateKey(self):
     privkey = FilePath(self.options["privkey"])
     if not privkey.isfile():
         log.err("Privkey is not file: %s" % privkey.path)
         return None
     try:
         #log.msg(privkey.path)
         return defer.succeed(keys.Key.fromFile(privkey.path))
     except keys.EncryptedKeyError:
         errmsg = "Encrypted private-key: %s" % privkey.path
         log.err(errmsg)
         return defer.fail(error.ConchError(errmsg))
Ejemplo n.º 8
0
 def getPublicKey(self):
     if self._tried_key:
         return
     pubkey = FilePath(self.options["pubkey"])
     if not pubkey.isfile():
         log.err("PublicKey is not file: %s" % pubkey.path)
         return None
     try:
         key = keys.Key.fromFile(pubkey.path)
         self._tried_key = True
         return key
     except keys.BadKeyError:
         log.err("PublicKey is bad: %s" % pubkey.path)
         return None
Ejemplo n.º 9
0
    def render_GET(self, request):
        """
        Create a custom or generic Login/Access to the Application.
        """
        file = FilePath('custom/unauthorized.py')
        if file.exists() and file.isfile() or file.islink():
            # Custom form is provided
            from custom.login import CustomLogin
            root = IResource(CustomLogin())
        else:
            from goliat.auth.login import Login
            from goliat.utils.config import ConfigManager
            root = IResource(
                Login(ConfigManager().get_config('Goliat')['Project']))

        request.setResponseCode(http.UNAUTHORIZED)
        return root.render(request)
Ejemplo n.º 10
0
    def render_GET(self, request):
        """
        Create a custom or generic Login/Access to the Application.
        """
        file=FilePath('custom/unauthorized.py')
        if file.exists() and file.isfile() or file.islink():
            # Custom form is provided
            from custom.login import CustomLogin
            root=IResource(CustomLogin())
        else:
            from goliat.auth.login import Login
            from goliat.utils.config import ConfigManager
            root=IResource(Login(
                ConfigManager().get_config('Goliat')['Project']))

        request.setResponseCode(http.UNAUTHORIZED)
        return root.render(request)
Ejemplo n.º 11
0
def main():
    address = FilePath(sys.argv[1])
    content = FilePath(sys.argv[2])

    if address.exists():
        raise SystemExit("Cannot listen on an existing path")

    if not content.isfile():
        raise SystemExit("Content file must exist")

    startLogging(sys.stdout)

    serverFactory = Factory()
    serverFactory.content = content
    serverFactory.protocol = SendFDProtocol

    port = reactor.listenUNIX(address.path, serverFactory)
    reactor.run()
Ejemplo n.º 12
0
def main():
    address = FilePath(sys.argv[1])
    content = FilePath(sys.argv[2])

    if address.exists():
        raise SystemExit("Cannot listen on an existing path")

    if not content.isfile():
        raise SystemExit("Content file must exist")

    startLogging(sys.stdout)

    serverFactory = Factory()
    serverFactory.content = content
    serverFactory.protocol = SendFDProtocol

    reactor.listenUNIX(address.path, serverFactory)
    reactor.run()
Ejemplo n.º 13
0
 def walk(self, path):
     containers = []
     filepath = FilePath(path)
     if filepath.isdir():
         containers.append(filepath)
     elif filepath.isfile():
         self.items.append(FilePath(path))
     while len(containers)>0:
         container = containers.pop()
         try:
             for child in container.children():
                 if child.isdir():
                     containers.append(child)
                 elif child.isfile() or child.islink():
                     mimetype,_ = mimetypes.guess_type(child.path, strict=False)
                     if mimetype and mimetype.startswith("image/"):
                         self.items.append(child)
         except UnicodeDecodeError:
             self.warning("UnicodeDecodeError - there is something wrong with a file located in %r", container.get_path())
Ejemplo n.º 14
0
#--------------------------------------------------------------------------------
# Log handler
#--------------------------------------------------------------------------------
if (debug):
    log.startLogging(sys.stdout)
else:
    logFile = logfile.LogFile("ip_streamer.log", "/tmp")
    log.startLogging(logFile)
    
#--------------------------------------------------------------------------------
# Read config, exit if no config is found
#--------------------------------------------------------------------------------
config = ConfigParser.ConfigParser()
path = FilePath('/etc/vice/config.ini')
if(FilePath.isfile(path)):
    config.read('/etc/vice/config.ini')
    viceIp = config.get('settings','server')
    vicePort = config.get('settings','port')
    viceServer = 'http://' + viceIp + ':' + vicePort
    updatetime = config.get('settings_mumudude','updatetime')
    tmpdir = FilePath(config.get('settings_mumudude','tmpdir'))
    if not FilePath.isdir(tmpdir):
        FilePath.createDirectory(tmpdir)
    mumudvblogdir = FilePath(config.get('settings_mumudude','mumudvblogdir'))
    if not FilePath.isdir(mumudvblogdir):
        FilePath.createDirectory(mumudvblogdir)
    mumudvbbindir = FilePath(config.get('settings_mumudude','mumudvbbindir'))   
    if not FilePath.isdir(mumudvbbindir):
        FilePath.createDirectory(mumudvbbindir)
else: