예제 #1
0
    def access_or_create_workdir_and_db(self):
        self.db = None
        db_stored_workdir = None
        db_state = None
        try:
            uri = self.parameters.get_simple("database")
            self.db = wudb.DBFactory(uri)
            self.logger.info("Attempting database access for URI %s" %
                             self.db.uri_without_credentials)
            db_state = query_db_path(db=self.db)
            db_stored_workdir = db_state.state["workdir"]
            self.logger.info("Found database, with stored workdir path %s" %
                             db_stored_workdir)
        except Exception as e:
            # self.logger.info("No database exists yet (%s)" % str(e))
            self.logger.info("No database exists yet")

        a = self.args.workdir
        b = db_stored_workdir
        if a and b and a != b:
            self.logger.critical(
                "Cannot have workdir provided both by the command line and the database in two different ways"
            )
        elif self.args.workdir:
            self.parameters.set_simple("tasks.workdir", self.args.workdir)
        elif db_stored_workdir:
            self.parameters.set_simple("tasks.workdir", db_stored_workdir)

        try:
            wdir = self.parameters.get_simple("tasks.workdir")
        except KeyError:
            wdir = tempfile.mkdtemp(prefix="cado.")
            self.logger.info("Created temporary directory %s" % wdir)
            self.parameters.set_simple("tasks.workdir", wdir)
            self.purge_files.append(wdir)
            if os.environ.get("CADO_DEBUG", None):
                self.logger.info("CADO_DEBUG is on, data will be kept in %s" %
                                 wdir)

        if not os.path.isdir(wdir):
            self.logger.debug("Created directory %s" % wdir)
            os.makedirs(wdir)

        if not db_state:
            name = self.parameters.get_simple("tasks.name", "cado-nfs")
            uri = self.parameters.get_simple(
                "database", "db:sqlite3://%s/%s.db" % (wdir, name))
            self.db = wudb.DBFactory(uri, create=True)
            db_state = query_db_path(db=self.db)

        db_state.state["workdir"] = wdir
예제 #2
0
    parser.add_argument("-cafile",
                        help="Certificate file name",
                        required=False)
    parser.add_argument("-threaded",
                        help="Use threaded server",
                        action="store_true",
                        default=False)
    parser.add_argument("-onlyreg",
                        help="Allow access only to registered files",
                        action="store_true",
                        default=False)
    args = parser.parse_args()

    PORT = int(args.port)
    HTTP = args.address
    dbdata = wudb.DBFactory(args.dburi)
    cafile = args.cafile
    registered_filenames = {}

    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)

    httpd = ServerLauncher(HTTP,
                           PORT,
                           args.threaded,
                           dbdata,
                           registered_filenames,
                           args.uploaddir,
                           only_registered=args.onlyreg,
                           cafile=cafile)