Beispiel #1
0
def show_file(request, project, label):
    show_script = request.GET.get('show_script', False)
    show_args = request.GET.get('show_args', False)
    digest = request.GET.get('digest', False)
    name = request.GET.get('name', False) # file name (in case of argument file)
    path = request.GET.get('path', False)
    path = str(path).encode("string_escape")
    if show_script: # record_list.html: user click the main file cell  
        if isinstance(get_repository(path), GitRepository):
            file_content = content_git(path, digest)
            return HttpResponse(file_content)
        elif isinstance(get_repository(path), MercurialRepository):
            file_content = content_mercurial(path, digest)
            return HttpResponse(file_content)
        return HttpResponse('Sorry, I cannot show you the content. Work only with GIT and Mercurial...')
    elif show_args:
        if 'fakepath' in name: # true for chrome
            name = name.split('\\')[-1]  # only for windows ???
        try:
            arg_file = open(os.getcwd() + '\\' + name, 'r')
            f_content = arg_file.read()
            arg_file.close()
        except:
            return HttpResponse('There is no file with this name in %s' %(os.getcwd()))
        return HttpResponse(f_content)
Beispiel #2
0
def show_file(request, project, label):
    show_script = request.GET.get('show_script', False)
    show_args = request.GET.get('show_args', False)
    digest = request.GET.get('digest', False)
    name = request.GET.get('name',
                           False)  # file name (in case of argument file)
    path = request.GET.get('path', False)
    path = str(path).encode("string_escape")
    if show_script:  # record_list.html: user click the main file cell
        if isinstance(get_repository(path), GitRepository):
            file_content = content_git(path, digest)
            return HttpResponse(file_content)
        elif isinstance(get_repository(path), MercurialRepository):
            file_content = content_mercurial(path, digest)
            return HttpResponse(file_content)
        return HttpResponse(
            'Sorry, I cannot show you the content. Work only with GIT and Mercurial...'
        )
    elif show_args:
        if 'fakepath' in name:  # true for chrome
            name = name.split('\\')[-1]  # only for windows ???
        try:
            arg_file = open(os.getcwd() + '\\' + name, 'r')
            f_content = arg_file.read()
            arg_file.close()
        except:
            return HttpResponse('There is no file with this name in %s' %
                                (os.getcwd()))
        return HttpResponse(f_content)
Beispiel #3
0
 def test__get_repository_from_working_copy(self):
     repos = SubversionRepository("file://%s/subversion" % self.basepath)
     tmpdir = tempfile.mkdtemp()
     repos.checkout(tmpdir)
     orig_dir = os.getcwd()
     os.chdir(tmpdir)
     repos1 = get_repository(None)
     os.chdir(orig_dir)
     self.assertEqual(repos, repos1)
     shutil.rmtree(tmpdir)
 def test__get_repository_from_working_copy(self):
     repos = SubversionRepository("file://%s/subversion" % self.basepath)
     tmpdir = tempfile.mkdtemp()
     repos.checkout(tmpdir)
     orig_dir = os.getcwd()
     os.chdir(tmpdir)
     repos1 = get_repository(None)
     os.chdir(orig_dir)
     self.assertEqual(repos, repos1)
     shutil.rmtree(tmpdir)
Beispiel #5
0
def configure(argv):
    """Modify the settings for the current project."""
    usage = "%(prog)s configure [options]"
    description = "Modify the settings for the current project."
    parser = ArgumentParser(usage=usage,
                            description=description)
    parser.add_argument('-d', '--datapath', metavar='PATH', help="set the path to the directory in which smt will search for datafiles generated by the simulation or analysis.")
    parser.add_argument('-i', '--input', metavar='PATH', default=None, help="set the path to the directory in which smt will search for input datafiles.")
    parser.add_argument('-l', '--addlabel', choices=['cmdline', 'parameters', None], metavar='OPTION',
                        default=None, help="If this option is set, smt will append the record label either to the command line (option 'cmdline') or to the parameter file (option 'parameters'), and will add the label to the datapath when searching for datafiles. It is up to the user to make use of this label inside their program to ensure files are created in the appropriate location.")
    parser.add_argument('-e', '--executable', metavar='PATH', help="set the path to the executable.")
    parser.add_argument('-r', '--repository', help="the URL of a Subversion or Mercurial repository containing the code. This will be checked out/cloned into the current directory.")
    parser.add_argument('-m', '--main', help="the name of the script that would be supplied on the command line if running the simulator normally, e.g. init.hoc.")
    parser.add_argument('-c', '--on-changed', help="may be 'store-diff' or 'error': the action to take if the code in the repository or any of the dependencies has changed.", choices=['store-diff', 'error'])
    parser.add_argument('-g', '--labelgenerator', choices=['timestamp', 'uuid'], metavar='OPTION', help="specify which method Sumatra should use to generate labels (options: timestamp, uuid)")
    parser.add_argument('-t', '--timestamp_format', help="the timestamp format given to strftime")
    parser.add_argument('-L', '--launch_mode', choices=['serial', 'distributed', 'slurm-mpi'], help="how computations should be launched.")
    parser.add_argument('-o', '--launch_mode_options', help="extra options for the given launch mode, to be given in quotes with a leading space, e.g. ' --foo=3'")
    parser.add_argument('-p', '--plain', dest='plain', action='store_true', help="pass arguments to the 'run' command straight through to the program. Otherwise arguments of the form name=value can be used to overwrite default parameter values.")
    parser.add_argument('--no-plain', dest='plain', action='store_false', help="arguments to the 'run' command of the form name=value will overwrite default parameter values. This is the opposite of the --plain option.")
    parser.add_argument('-s', '--store', help="Change the record store to the specified path, URL or URI (must be specified). {0}".format(store_arg_help))

    datastore = parser.add_mutually_exclusive_group()
    datastore.add_argument('-W', '--webdav', metavar='URL', help="specify a webdav URL (with username@password: if needed) as the archiving location for data")
    datastore.add_argument('-A', '--archive', metavar='PATH', help="specify a directory in which to archive output datafiles. If not specified, or if 'false', datafiles are not archived.")
    datastore.add_argument('-M', '--mirror', metavar='URL', help="specify a URL at which your datafiles will be mirrored.")

    parser.add_argument('--add-plugin', help="name of a Python module containing one or more plug-ins.")
    parser.add_argument('--remove-plugin', help="name of a plug-in module to remove from the project.")

    args = parser.parse_args(argv)

    project = load_project()
    if args.store:
        new_store = get_record_store(args.store)
        project.change_record_store(new_store)
    if args.datapath:
        project.data_store.root = args.datapath
    if args.archive:
        if args.archive.lower() == "true":
            args.archive = ".smt/archive"
        if hasattr(project.data_store, 'archive_store'):  # current data store is archiving
            if args.archive.lower() == 'false':
                project.data_store = get_data_store("FileSystemDataStore",
                                                    {"root": project.data_store.root})
            else:
                project.data_store.archive_store = args.archive
        else:  # current data store is not archiving
            if args.archive.lower() != 'false':
                project.data_store = get_data_store("ArchivingFileSystemDataStore",
                                                    {"root": project.data_store.root, "archive": args.archive})
    elif args.mirror:
        project.data_store = get_data_store("MirroredFileSystemDataStore",
                                            {"root": project.data_store.root, "mirror_base_url": args.mirror})
    elif args.webdav:
        # should we care about archive migration??
        project.data_store = get_data_store("DavFsDataStore",
                                            {"root": project.data_store.root, "dav_url": args.webdav})
        project.data_store.archive_store = '.smt/archive'
    if args.input:
        project.input_datastore.root = args.input
    if args.repository:
        repository = get_repository(args.repository)
        repository.checkout()
        project.default_repository = repository
    if args.main:
        project.default_main_file = args.main
    if args.executable:
        executable_path, executable_options = parse_executable_str(args.executable)
        project.default_executable = get_executable(executable_path,
                                                    script_file=args.main or project.default_main_file)
        project.default_executable.options = executable_options

    if args.on_changed:
        project.on_changed = args.on_changed
    if args.addlabel:
        project.data_label = args.addlabel
    if args.labelgenerator:
        project.label_generator = args.labelgenerator
    if args.timestamp_format:
        project.timestamp_format = args.timestamp_format
    if args.launch_mode:
        project.default_launch_mode = get_launch_mode(args.launch_mode)()
    if args.launch_mode_options:
        project.default_launch_mode.options = args.launch_mode_options.strip()
    if args.plain is not None:
        project.allow_command_line_parameters = not args.plain
    if args.add_plugin:
        project.load_plugins(args.add_plugin)
    if args.remove_plugin:
        project.remove_plugins(args.remove_plugin)
    project.save()
Beispiel #6
0
def init(argv):
    """Create a new project in the current directory."""
    usage = "%(prog)s init [options] NAME"
    description = "Create a new project called NAME in the current directory."
    parser = ArgumentParser(usage=usage,
                            description=description)
    parser.add_argument('project_name', metavar='NAME', help="a short name for the project; should not contain spaces.")
    parser.add_argument('-d', '--datapath', metavar='PATH', default='./Data', help="set the path to the directory in which smt will search for output datafiles generated by the simulation/analysis. Defaults to %(default)s.")
    parser.add_argument('-i', '--input', metavar='PATH', default='/', help="set the path to the directory relative to which input datafile paths will be given. Defaults to the filesystem root.")
    parser.add_argument('-l', '--addlabel', choices=['cmdline', 'parameters', None], metavar='OPTION',
                        default=None, help="If this option is set, smt will append the record label either to the command line (option 'cmdline') or to the parameter file (option 'parameters'), and will add the label to the datapath when searching for datafiles. It is up to the user to make use of this label inside their program to ensure files are created in the appropriate location.")
    parser.add_argument('-e', '--executable', metavar='PATH', help="set the path to the executable. If this is not set, smt will try to infer the executable from the value of the --main option, if supplied, and will try to find the executable from the PATH environment variable, then by searching various likely locations on the filesystem.")
    parser.add_argument('-r', '--repository', help="the URL of a Subversion or Mercurial repository containing the code. This will be checked out/cloned into the current directory.")
    parser.add_argument('-m', '--main', help="the name of the script that would be supplied on the command line if running the simulation or analysis normally, e.g. init.hoc.")
    parser.add_argument('-c', '--on-changed', default='error', help="the action to take if the code in the repository or any of the depdendencies has changed. Defaults to %(default)s")  # need to add list of allowed values
    parser.add_argument('-s', '--store', help="Specify the path, URL or URI to the record store (must be specified). This can either be an existing record store or one to be created. {0} Not using the `--store` argument defaults to a DjangoRecordStore with Sqlite in `.smt/records`".format(store_arg_help))
    parser.add_argument('-g', '--labelgenerator', choices=['timestamp', 'uuid'], default='timestamp', metavar='OPTION', help="specify which method Sumatra should use to generate labels (options: timestamp, uuid)")
    parser.add_argument('-t', '--timestamp_format', help="the timestamp format given to strftime", default=TIMESTAMP_FORMAT)
    parser.add_argument('-L', '--launch_mode', choices=['serial', 'distributed', 'slurm-mpi'], default='serial', help="how computations should be launched. Defaults to %(default)s")
    parser.add_argument('-o', '--launch_mode_options', help="extra options for the given launch mode")

    datastore = parser.add_mutually_exclusive_group()
    datastore.add_argument('-W', '--webdav', metavar='URL', help="specify a webdav URL (with username@password: if needed) as the archiving location for data")
    datastore.add_argument('-A', '--archive', metavar='PATH', help="specify a directory in which to archive output datafiles. If not specified, or if 'false', datafiles are not archived.")
    datastore.add_argument('-M', '--mirror', metavar='URL', help="specify a URL at which your datafiles will be mirrored.")

    args = parser.parse_args(argv)

    try:
        project = load_project()
        parser.error("A project already exists in directory '{0}'.".format(project.path))
    except Exception:
        pass

    if not os.path.exists(".smt"):
        os.mkdir(".smt")

    if args.repository:
        repository = get_repository(args.repository)
        repository.checkout()
    else:
        repository = get_working_copy().repository  # if no repository is specified, we assume there is a working copy in the current directory.

    if args.executable:
        executable_path, executable_options = parse_executable_str(args.executable)
        executable = get_executable(path=executable_path)
        executable.args = executable_options
    elif args.main:
        try:
            executable = get_executable(script_file=args.main)
        except Exception:  # assume unrecognized extension - really need more specific exception type
            # should warn that extension unrecognized
            executable = None
    else:
        executable = None
    if args.store:
        record_store = get_record_store(args.store)
    else:
        record_store = 'default'

    if args.webdav:
        # should we care about archive migration??
        output_datastore = get_data_store("DavFsDataStore", {"root": args.datapath, "dav_url": args.webdav})
        args.archive = '.smt/archive'
    elif args.archive and args.archive.lower() != 'false':
        if args.archive.lower() == "true":
            args.archive = ".smt/archive"
        args.archive = os.path.abspath(args.archive)
        output_datastore = get_data_store("ArchivingFileSystemDataStore", {"root": args.datapath, "archive": args.archive})
    elif args.mirror:
        output_datastore = get_data_store("MirroredFileSystemDataStore", {"root": args.datapath, "mirror_base_url": args.mirror})
    else:
        output_datastore = get_data_store("FileSystemDataStore", {"root": args.datapath})
    input_datastore = get_data_store("FileSystemDataStore", {"root": args.input})

    if args.launch_mode_options:
        args.launch_mode_options = args.launch_mode_options.strip()
    launch_mode = get_launch_mode(args.launch_mode)(options=args.launch_mode_options)

    project = Project(name=args.project_name,
                      default_executable=executable,
                      default_repository=repository,
                      default_main_file=args.main,  # what if incompatible with executable?
                      default_launch_mode=launch_mode,
                      data_store=output_datastore,
                      record_store=record_store,
                      on_changed=args.on_changed,
                      data_label=args.addlabel,
                      input_datastore=input_datastore,
                      label_generator=args.labelgenerator,
                      timestamp_format=args.timestamp_format)
    if os.path.exists('.smt') and project.record_store.has_project(project.name):
        f = open('.smt/labels', 'w')
        f.writelines(project.format_records(tags=None, mode='short', format='text', reverse=False))
        f.close()
    project.save()
Beispiel #7
0
def configure(argv):
    """Modify the settings for the current project."""
    usage = "%(prog)s configure [options]"
    description = "Modify the settings for the current project."
    parser = ArgumentParser(usage=usage,
                            description=description)
    parser.add_argument('-d', '--datapath', metavar='PATH', help="set the path to the directory in which smt will search for datafiles generated by the simulation or analysis.")
    parser.add_argument('-i', '--input', metavar='PATH', default=None, help="set the path to the directory in which smt will search for input datafiles.")
    parser.add_argument('-l', '--addlabel', choices=['cmdline', 'parameters', None], metavar='OPTION',
                        default=None, help="If this option is set, smt will append the record label either to the command line (option 'cmdline') or to the parameter file (option 'parameters'), and will add the label to the datapath when searching for datafiles. It is up to the user to make use of this label inside their program to ensure files are created in the appropriate location.")
    parser.add_argument('-e', '--executable', metavar='PATH', help="set the path to the executable.")
    parser.add_argument('-r', '--repository', help="the URL of a Subversion or Mercurial repository containing the code. This will be checked out/cloned into the current directory.")
    parser.add_argument('-m', '--main', help="the name of the script that would be supplied on the command line if running the simulator normally, e.g. init.hoc.")
    parser.add_argument('-c', '--on-changed', help="may be 'store-diff' or 'error': the action to take if the code in the repository or any of the dependencies has changed.", choices=['store-diff', 'error'])
    parser.add_argument('-g', '--labelgenerator', choices=['timestamp', 'uuid'], metavar='OPTION', help="specify which method Sumatra should use to generate labels (options: timestamp, uuid)")
    parser.add_argument('-t', '--timestamp_format', help="the timestamp format given to strftime")
    parser.add_argument('-L', '--launch_mode', choices=['serial', 'distributed', 'slurm-mpi'], help="how computations should be launched.")
    parser.add_argument('-o', '--launch_mode_options', help="extra options for the given launch mode, to be given in quotes with a leading space, e.g. ' --foo=3'")
    parser.add_argument('-p', '--plain', action='store_true', help="pass arguments to the run command straight through to the program.")
    parser.add_argument('-s', '--store', help="Change the record store to the specified path, URL or URI (must be specified). {0}".format(store_arg_help))

    datastore = parser.add_mutually_exclusive_group()
    datastore.add_argument('-W', '--webdav', metavar='URL', help="specify a webdav URL (with username@password: if needed) as the archiving location for data")
    datastore.add_argument('-A', '--archive', metavar='PATH', help="specify a directory in which to archive output datafiles. If not specified, or if 'false', datafiles are not archived.")
    datastore.add_argument('-M', '--mirror', metavar='URL', help="specify a URL at which your datafiles will be mirrored.")

    args = parser.parse_args(argv)

    project = load_project()
    if args.store:
        new_store = get_record_store(args.store)
        project.change_record_store(new_store)

    if args.archive:
        if args.archive.lower() == "true":
            args.archive = ".smt/archive"
        if hasattr(project.data_store, 'archive_store'):  # current data store is archiving
            if args.archive.lower() == 'false':
                project.data_store = get_data_store("FileSystemDataStore", {"root": project.data_store.root})
            else:
                project.data_store.archive_store = args.archive
        else:  # current data store is not archiving
            if args.archive.lower() != 'false':
                project.data_store = get_data_store("ArchivingFileSystemDataStore", {"root": args.datapath, "archive": args.archive})
    if args.webdav:
        # should we care about archive migration??
        project.data_store = get_data_store("DavFsDataStore", {"root": args.datapath, "dav_url": args.webdav})
        project.data_store.archive_store = '.smt/archive'
    if args.datapath:
        project.data_store.root = args.datapath
    if args.input:
        project.input_datastore.root = args.input
    if args.repository:
        repository = get_repository(args.repository)
        repository.checkout()
        project.default_repository = repository
    if args.main:
        project.default_main_file = args.main
    if args.executable:
        executable_path, executable_options = parse_executable_str(args.executable)
        project.default_executable = get_executable(executable_path,
                                                    script_file=args.main or project.default_main_file)
        project.default_executable.options = executable_options

    if args.on_changed:
        project.on_changed = args.on_changed
    if args.addlabel:
        project.data_label = args.addlabel
    if args.labelgenerator:
        project.label_generator = args.labelgenerator
    if args.timestamp_format:
        project.timestamp_format = args.timestamp_format
    if args.launch_mode:
        project.default_launch_mode = get_launch_mode(args.launch_mode)()
    if args.launch_mode_options:
        project.default_launch_mode.options = args.launch_mode_options.strip()
    if args.plain:
        project.allow_command_line_parameters = False
    project.save()
Beispiel #8
0
def init(argv):
    """Create a new project in the current directory."""
    usage = "%(prog)s init [options] NAME"
    description = "Create a new project called NAME in the current directory."
    parser = ArgumentParser(usage=usage,
                            description=description)
    parser.add_argument('project_name', metavar='NAME', help="a short name for the project; should not contain spaces.")
    parser.add_argument('-d', '--datapath', metavar='PATH', default='./Data', help="set the path to the directory in which smt will search for output datafiles generated by the simulation/analysis. Defaults to %(default)s.")
    parser.add_argument('-i', '--input', metavar='PATH', default='/', help="set the path to the directory relative to which input datafile paths will be given. Defaults to the filesystem root.")
    parser.add_argument('-l', '--addlabel', choices=['cmdline', 'parameters', None], metavar='OPTION',
                        default=None, help="If this option is set, smt will append the record label either to the command line (option 'cmdline') or to the parameter file (option 'parameters'), and will add the label to the datapath when searching for datafiles. It is up to the user to make use of this label inside their program to ensure files are created in the appropriate location.")
    parser.add_argument('-e', '--executable', metavar='PATH', help="set the path to the executable. If this is not set, smt will try to infer the executable from the value of the --main option, if supplied, and will try to find the executable from the PATH environment variable, then by searching various likely locations on the filesystem.")
    parser.add_argument('-r', '--repository', help="the URL of a Subversion or Mercurial repository containing the code. This will be checked out/cloned into the current directory.")
    parser.add_argument('-m', '--main', help="the name of the script that would be supplied on the command line if running the simulation or analysis normally, e.g. init.hoc.")
    parser.add_argument('-c', '--on-changed', default='error', help="the action to take if the code in the repository or any of the depdendencies has changed. Defaults to %(default)s")  # need to add list of allowed values
    parser.add_argument('-s', '--store', help="Specify the path, URL or URI to the record store (must be specified). This can either be an existing record store or one to be created. {0} Not using the `--store` argument defaults to a DjangoRecordStore with Sqlite in `.smt/records`".format(store_arg_help))
    parser.add_argument('-g', '--labelgenerator', choices=['timestamp', 'uuid'], default='timestamp', metavar='OPTION', help="specify which method Sumatra should use to generate labels (options: timestamp, uuid)")
    parser.add_argument('-t', '--timestamp_format', help="the timestamp format given to strftime", default=TIMESTAMP_FORMAT)
    parser.add_argument('-L', '--launch_mode', choices=['serial', 'distributed', 'slurm-mpi'], default='serial', help="how computations should be launched. Defaults to %(default)s")
    parser.add_argument('-o', '--launch_mode_options', help="extra options for the given launch mode")

    datastore = parser.add_mutually_exclusive_group()
    datastore.add_argument('-W', '--webdav', metavar='URL', help="specify a webdav URL (with username@password: if needed) as the archiving location for data")
    datastore.add_argument('-A', '--archive', metavar='PATH', help="specify a directory in which to archive output datafiles. If not specified, or if 'false', datafiles are not archived.")
    datastore.add_argument('-M', '--mirror', metavar='URL', help="specify a URL at which your datafiles will be mirrored.")

    args = parser.parse_args(argv)

    try:
        project = load_project()
        parser.error("A project already exists in this directory.")
    except Exception:
        pass

    if not os.path.exists(".smt"):
        os.mkdir(".smt")

    if args.repository:
        repository = get_repository(args.repository)
        repository.checkout()
    else:
        repository = get_working_copy().repository  # if no repository is specified, we assume there is a working copy in the current directory.

    if args.executable:
        executable_path, executable_options = parse_executable_str(args.executable)
        executable = get_executable(path=executable_path)
        executable.args = executable_options
    elif args.main:
        try:
            executable = get_executable(script_file=args.main)
        except Exception:  # assume unrecognized extension - really need more specific exception type
            # should warn that extension unrecognized
            executable = None
    else:
        executable = None
    if args.store:
        record_store = get_record_store(args.store)
    else:
        record_store = 'default'

    if args.webdav:
        # should we care about archive migration??
        output_datastore = get_data_store("DavFsDataStore", {"root": args.datapath, "dav_url": args.webdav})
        args.archive = '.smt/archive'
    elif args.archive and args.archive.lower() != 'false':
        if args.archive.lower() == "true":
            args.archive = ".smt/archive"
        args.archive = os.path.abspath(args.archive)
        output_datastore = get_data_store("ArchivingFileSystemDataStore", {"root": args.datapath, "archive": args.archive})
    elif args.mirror:
        output_datastore = get_data_store("MirroredFileSystemDataStore", {"root": args.datapath, "mirror_base_url": args.mirror})
    else:
        output_datastore = get_data_store("FileSystemDataStore", {"root": args.datapath})
    input_datastore = get_data_store("FileSystemDataStore", {"root": args.input})

    if args.launch_mode_options:
        args.launch_mode_options = args.launch_mode_options.strip()
    launch_mode = get_launch_mode(args.launch_mode)(options=args.launch_mode_options)

    project = Project(name=args.project_name,
                      default_executable=executable,
                      default_repository=repository,
                      default_main_file=args.main,  # what if incompatible with executable?
                      default_launch_mode=launch_mode,
                      data_store=output_datastore,
                      record_store=record_store,
                      on_changed=args.on_changed,
                      data_label=args.addlabel,
                      input_datastore=input_datastore,
                      label_generator=args.labelgenerator,
                      timestamp_format=args.timestamp_format)
    project.save()
Beispiel #9
0
 def test__get_repository__from_url(self):
     if have_pysvn:
         repos = get_repository("file://%s/subversion" % self.basepath)
         assert isinstance(repos, SubversionRepository)
     repos = get_repository("file://%s/mercurial" % self.basepath)
     assert isinstance(repos, MercurialRepository), type(repos)
Beispiel #10
0
 def test__get_repository__from_url(self):
     if have_pysvn:
         repos = get_repository("file://%s/subversion" % self.basepath)
         assert isinstance(repos, SubversionRepository)
     repos = get_repository("file://%s/mercurial" % self.basepath)
     assert isinstance(repos, MercurialRepository), type(repos)