示例#1
0
    def copy_sobject(my,
                     sobject,
                     dst_search_type,
                     context=None,
                     checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id', 'code', 'pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue
            new_sobject.set_value(name, value)

        new_sobject.commit()

        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject,
                                      context=context,
                                      file_paths=file_paths,
                                      file_types=file_types,
                                      mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %
                            (context, e.__str__()))
示例#2
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name , 'naming_test_folder_naming_base_test_v002')
        
        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name , '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name , 'naming_test_folder3_naming_base_test_v003')


        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v004')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
示例#3
0
    def _check_in_swf(my, snapshot, sobject, render, pat, final_pat,
                      render_dir, filenames):
        final_path = icon_path = ''
        for name in filenames:
            if pat.match(name):
                final_name = pat.sub(final_pat, name)
                shutil.move(render_dir + "/" + name, render_dir \
                    + "/" + final_name)
                src_path = "%s/%s" % (render_dir, final_name)
                if final_name.endswith('.png'):
                    icon_creator = IconCreator(src_path)
                    icon_creator.create_icons()
                    icon_path = icon_creator.get_icon_path()
                elif final_name.endswith('.swf'):
                    final_path = src_path
        types = ["main"]
        paths = [final_path]

        if icon_path:
            paths.append(icon_path)
            types.append('icon')
        checkin = FileCheckin(render,
                              paths,
                              types,
                              context="render",
                              column="images")
        checkin.execute()
示例#4
0
    def copy_sobject(my, sobject, dst_search_type, context=None, checkin_mode='inplace'):

        new_sobject = SearchType.create(dst_search_type)
        search_type = SearchType.get(dst_search_type)
        columns = SearchType.get_columns(dst_search_type)

        data = sobject.get_data()
        for name, value in data.items():
            if name in ['id','pipeline_code']:
                continue

            if name not in columns:
                continue

            if not value:
                continue

            if name == "code":
                value = Common.get_next_sobject_code(sobject, 'code')
                if not value:
                    continue
            new_sobject.set_value(name, value)
        if SearchType.column_exists(dst_search_type, "project_code"):
            project_code = Project.get_project_code()
            new_sobject.set_value("project_code", project_code)
        new_sobject.commit()



        # get all of the current snapshots and file paths associated
        if not context:
            snapshots = Snapshot.get_all_current_by_sobject(sobject)
        else:
            snapshots = [Snapshot.get_current_by_sobject(sobject, context)]

        if not snapshots:
            return

        msgs = []
        for snapshot in snapshots:
            #file_paths = snapshot.get_all_lib_paths()
            file_paths_dict = snapshot.get_all_paths_dict()
            file_types = file_paths_dict.keys()
            if not file_types:
                continue

            # make sure the paths match the file_types
            file_paths = [file_paths_dict.get(x)[0] for x in file_types]

            mode = checkin_mode

            # checkin the files (inplace)
            try:
                context = snapshot.get_value('context')
                checkin = FileCheckin(new_sobject, context=context, file_paths=file_paths, file_types=file_types, mode=mode)
                checkin.execute()

                #print "done: ", context, new_sobject.get_related_sobjects("sthpw/snapshot")
            except CheckinException, e:
                msgs.append('Post-process Check-in Error for %s: %s ' %(context, e.__str__()))
示例#5
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name, 'naming_test_folder_naming_base_test_v002')

        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name, '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name, 'naming_test_folder3_naming_base_test_v003')

        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person,
                              dir_path4,
                              "main",
                              context='naming_base_test',
                              snapshot_type='directory',
                              checkin_type='')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name, 'generic_phil_v004')
        my.assertEquals(lib_dir, 'unittest/cut/generic/phil')
示例#6
0
    def _test_copycheckin(self):

        # create a new copy_test.txt file
        file_path = "./copy_test.txt"
        file = open(file_path, 'w')
        file.write("copy contents")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(
                    self.person,
                    file_paths=file_paths,
                    file_types=file_types,
                    context=context,
                    mode="copy"
            )
        checkin.execute()
        self.assertEquals(True, os.path.exists(file_path) )

        snap = checkin.get_snapshot()
        file_obj = snap.get_file_by_type('main')
        file_name = file_obj.get_file_name()
        self.assertEquals(file_name, 'copy_test_publish_v002.txt')
示例#7
0
    def _test_base_dir_alias(my):

        Config.set_value(
            "checkin", "asset_base_dir", {
                'default': '/tmp/tactic/default',
                'alias': '/tmp/tactic/alias',
                'alias2': '/tmp/tactic/alias2',
            })
        asset_dict = Environment.get_asset_dirs()
        default_dir = asset_dict.get("default")
        my.assertEquals("/tmp/tactic/default", default_dir)

        aliases = asset_dict.keys()
        # "plugins" is assumed in some branch
        if 'plugins' in aliases:
            my.assertEquals(4, len(aliases))
        else:
            my.assertEquals(3, len(aliases))
        my.assertNotEquals(None, "alias" in aliases)

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias")
        naming.set_value("dir_naming", "alias")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("base_dir_alias", "alias")
        naming.commit()

        # create 2nd naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias2")
        naming.set_value("dir_naming", "alias2")
        naming.set_value("base_dir_alias", "alias2")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("checkin_type", "auto")
        naming.commit()

        my.clear_naming()

        # create a new test.txt file
        for context in ['alias', 'alias2']:
            file_path = "./test.txt"
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()

            checkin = FileCheckin(my.person, file_path, context=context)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            lib_dir = snapshot.get_lib_dir()
            expected = "/tmp/tactic/%s/%s" % (context, context)
            my.assertEquals(expected, lib_dir)

            path = "%s/text.txt" % (lib_dir)
            exists = os.path.exists(path)
            my.assertEquals(True, exists)
示例#8
0
    def _test_base_dir_alias(my):

        Config.set_value("checkin", "asset_base_dir", {
            'default': '/tmp/tactic/default',
            'alias': '/tmp/tactic/alias',
            'alias2': '/tmp/tactic/alias2',
        });
        asset_dict = Environment.get_asset_dirs()
        default_dir = asset_dict.get("default")
        my.assertEquals( "/tmp/tactic/default", default_dir)

        aliases = asset_dict.keys()
        # "plugins" is assumed in some branch 
        if 'plugins' in aliases:
            my.assertEquals( 4, len(aliases))
        else:
            my.assertEquals( 3, len(aliases))
        my.assertNotEquals( None, "alias" in aliases )

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias")
        naming.set_value("dir_naming", "alias")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("base_dir_alias", "alias")
        naming.commit()

        # create 2nd naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "alias2")
        naming.set_value("dir_naming", "alias2")
        naming.set_value("base_dir_alias", "alias2")
        naming.set_value("file_naming", "text.txt")
        naming.set_value("checkin_type", "auto")
        naming.commit()

        my.clear_naming()

        # create a new test.txt file
        for context in ['alias', 'alias2']:
            file_path = "./test.txt"
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()

            checkin = FileCheckin(my.person, file_path, context=context)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            lib_dir = snapshot.get_lib_dir()
            expected = "/tmp/tactic/%s/%s" % (context, context)
            my.assertEquals(expected, lib_dir)

            path = "%s/text.txt" % (lib_dir)
            exists = os.path.exists(path)
            my.assertEquals(True, exists)
示例#9
0
    def execute(my):   
        import urllib
        from pyasm.checkin import FileCheckin
        from pyasm.search import Search
        pic_dict = {}
        pics = []
        order_dict = {}
        for ocode in my.orders:
            order = my.server.eval("@SOBJECT(twog/order['code','%s'])" % ocode)[0]
            ord_s = Search('twog/order')
            ord_s.add_filter('code',ocode)
            order = ord_s.get_sobject()
            if order:
                order_dict[ocode] = order
                poster = order.get_value('imdb_poster_url')
                if poster not in pics:
                    pics.append(poster)
                    pic_dict[poster] = [ocode]
                else:
                    pic_dict[poster].append(ocode)
        pic_places = {}
        number = 0
        for pic in pics:
            extension_s = pic.split('.')
            extension = extension_s[len(extension_s) - 1]
            place = '/var/www/html/imdb_images/associator%s.%s' % (number, extension) 
            f = open(place,'wb')
            f.write(urllib.urlopen(pic).read())
            f.close()
            pic_places[pic] = place
            number = number + 1

        for pic in pics:
            server_path = pic_places[pic]
            linked_orders = pic_dict[pic]
            for ocode in linked_orders: 
                sobject = order_dict[ocode]
                if sobject:
                    file_types = ['main']
                    context = "icon"
                    checkin = FileCheckin(
                        sobject,
                        file_paths=server_path,
                        file_types=file_types,
                        context=context,
                        mode="copy"
                    )
                    checkin.execute()

        
            

        return ''
示例#10
0
    def _test_data_flow(my):

        # create a dummy sobject
        sobject = SearchType.create("unittest/city")
        sobject.commit()

        # check in a file to the city
        file_path = "./ttteeesssttt.txt"
        file = open(file_path, 'w')
        file.write("test test test")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(
                    sobject,
                    file_paths=file_paths,
                    file_types=file_types,
                    context="fla",
                    mode="move"
            )
        checkin.execute()


        # create a pipeline
        pipeline_xml = '''
        <pipeline>
          <process type="auto" name="a"/>
          <process type="auto" name="b"/>
          <process type="approval" name="c"/>
          <connect from="a" to="b"/>
          <connect from="b" to="c"/>
        </pipeline>
        '''
        pipeline, processes = my.get_pipeline(pipeline_xml)

        sobject.set_value("pipeline_code", pipeline.get_code())
        sobject.commit()


        process = processes.get("a")
        process.set_json_value("workflow", {
            'output': {
                'sobject': 'sobject',
                'process': 'fla',
                'version': 'latest',
            }
            'checkin': ['fla'],
        } )
示例#11
0
    def postprocess(my):

        if my.sobject.is_general_asset():
            return
        # check to see if there are any snapshots
        # context is specified here to ignore any icon snapshots
        snapshot = Snapshot.get_latest_by_sobject(my.sobject,
                                                  context='publish')

        if snapshot:
            return

        column = "snapshot"
        new_file_paths = []
        file_paths = []
        # copy the default file to /tmp
        template_code = my.get_default_code()
        template = my.get_template_obj()
        if template:
            template_code = template.get_value('code')
            tmpl_snapshot = Snapshot.get_latest_by_sobject(template)

            file_paths = tmpl_snapshot.get_all_lib_paths()
        else:
            file_types = ['.fla', '.png', '_icon.png', '.swf']
            # TODO: this is a web depedency we don't need
            from pyasm.web import WebContainer
            web = WebContainer.get_web()
            for type in file_types:
                file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \
                    template_code, type))

        for file_path in file_paths:
            # rename and copy each file to /tmp
            base_name = os.path.basename(file_path)
            base_name = File.remove_file_code(base_name)
            base_name = base_name.replace(template_code, \
                my.get_naming().get_current_code(my.sobject) )

            # do a straight copy : No undo
            tmp_dir = Environment.get_tmp_dir()
            new_file_path = "%s/download/%s" % (tmp_dir, base_name)
            shutil.copyfile(file_path, new_file_path)
            new_file_paths.append(new_file_path)

        file_types = [".fla", ".png", "icon", ".swf"]
        checkin = FileCheckin( my.sobject, new_file_paths, file_types, \
            snapshot_type="flash", column=column  )
        checkin.execute()
示例#12
0
    def postprocess(my):

        if my.sobject.is_general_asset():
            return
        # check to see if there are any snapshots
        # context is specified here to ignore any icon snapshots
        snapshot = Snapshot.get_latest_by_sobject(my.sobject, context='publish')

        if snapshot:
            return

        column = "snapshot"
        new_file_paths = []
        file_paths = []
        # copy the default file to /tmp
        template_code = my.get_default_code()
        template = my.get_template_obj()
        if template:
            template_code = template.get_value('code')
            tmpl_snapshot = Snapshot.get_latest_by_sobject(template)
                    
            file_paths = tmpl_snapshot.get_all_lib_paths()
        else:
            file_types = ['.fla','.png','_icon.png','.swf']    
            # TODO: this is a web depedency we don't need
            from pyasm.web import WebContainer
            web = WebContainer.get_web()
            for type in file_types:
                file_paths.append('%s/template/%s%s' % (web.get_context_dir(), \
                    template_code, type))
                
        for file_path in file_paths:
            # rename and copy each file to /tmp
            base_name = os.path.basename(file_path)
            base_name = File.remove_file_code(base_name)
            base_name = base_name.replace(template_code, \
                my.get_naming().get_current_code(my.sobject) )
            
            # do a straight copy : No undo
            tmp_dir = Environment.get_tmp_dir()
            new_file_path = "%s/download/%s" % (tmp_dir,base_name)
            shutil.copyfile(file_path, new_file_path)
            new_file_paths.append(new_file_path)


        file_types = [".fla", ".png", "icon",".swf"]
        checkin = FileCheckin( my.sobject, new_file_paths, file_types, \
            snapshot_type="flash", column=column  )
        checkin.execute()
示例#13
0
    def postprocess(my):
        web = get_web_container()
        my.files = []
        my.file_types = []
        
        my._upload_zipped_files()

        context = my.get_value("%s|context" % my.name)
        description = my.get_value("%s|description" % my.name)

        # let checkin take care of moving files to the lib
        from pyasm.checkin import FileCheckin
        for sobject in my.sobject_dict.keys():
            files, file_types = my.sobject_dict.get(sobject)
            my.checkin = FileCheckin.get( sobject, files, file_types,  \
                context=context, snapshot_type="file" )
            my.checkin.set_description(description)
            my.checkin.execute()

           
       
        # remove the files in upload area
        for key in my.sobject_dict.keys():
            files, file_types = my.sobject_dict.get(key)
            for file in files:
                os.unlink(file)
示例#14
0
    def postprocess(my):
        web = get_web_container()
        my.files = []
        my.file_types = []
        if my.get_option('upload_type') == 'arbitrary':
            my._upload_arbitrary_files()
        else:
            my._upload_specified_files()

        context = my.get_value("%s|context" % my.name)
        subcontext = my.get_value("%s|subcontext" % my.name)
        if subcontext:
            context = '%s/%s' % (context, subcontext)
        description = my.get_value("%s|description" % my.name)
        from pyasm.widget import CheckboxWdg
        cb = CheckboxWdg("%s|is_revision" % my.get_input_name())
        is_rev = cb.is_checked(False)

        # let checkin take care of moving files to the lib
        from pyasm.checkin import FileCheckin
        my.checkin = FileCheckin.get( my.sobject, my.files, my.file_types,  \
            context=context, snapshot_type="file" )
        my.checkin.set_description(description)
        my.checkin.set_revision(is_rev)
        my.checkin.execute()

        my.sobjects.append(my.sobject)
        my.info['context'] = context
        my.add_description('File Publish for [%s]' % my.sobject.get_code())
        # remove the files in upload area
        for file in my.files:
            if os.path.exists(file):
                os.unlink(file)

        Trigger.call(my, "email")
示例#15
0
    def postprocess(self):
        web = get_web_container()
        self.files = []
        self.file_types = []
        
        self._upload_zipped_files()

        context = self.get_value("%s|context" % self.name)
        description = self.get_value("%s|description" % self.name)

        # let checkin take care of moving files to the lib
        from pyasm.checkin import FileCheckin
        for sobject in self.sobject_dict.keys():
            files, file_types = self.sobject_dict.get(sobject)
            self.checkin = FileCheckin.get( sobject, files, file_types,  \
                context=context, snapshot_type="file" )
            self.checkin.set_description(description)
            self.checkin.execute()

           
       
        # remove the files in upload area
        for key in self.sobject_dict.keys():
            files, file_types = self.sobject_dict.get(key)
            for file in files:
                os.unlink(file)
示例#16
0
    def _parse_form(my):

        # get the downloaded files and sort them
        web = WebContainer.get_web()

        my.upload_values.sort()

        filenames = []
        ticket = web.get_cookie("login_ticket")
        # create a new entry for every file
        for upload_value in my.upload_values:
            tmp_dir = Environment.get_tmp_dir()
            basename = os.path.basename(upload_value)
            file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename)

            filenames.append(basename)

            creator = IconCreator(file_path)
            creator.create_icons()

            my.file_paths = [file_path]
            file_types = ["main"]

            web_path = creator.get_web_path()
            if web_path != None:
                my.file_paths.append(web_path)
                file_types.append("web")

            icon_path = creator.get_icon_path()
            if icon_path != None:
                my.file_paths.append(icon_path)
                file_types.append("icon")

            sobject = None
            if my.search_key:
                sobject = Search.get_by_search_key(my.search_key)
            else:
                sobject = SObjectFactory.create(my.search_type)
                sobject.commit()

            checkin = FileCheckin(sobject, my.file_paths, file_types, column=my.column)

            checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT))
            checkin.execute()
            my.repo_file_list.append(checkin.file_dict)

        my.description = "Added files: %s" % filenames
示例#17
0
文件: command.py 项目: nuxping/TACTIC
    def execute(my):
        print "EXECUTING sample command"

        # create the render
        render = SearchType.create("prod/render")
        render.set_parent(my.prev_command.sobject)
        render.set_value("pipeline_code", "turntable")
        render.commit()
        Task.add_initial_tasks(render)

        prev_sobject = my.prev_command.sobject
        prev_process = "model"
        this_sobject = my.prev_command.sobject
        this_process = "turntable"

        # get the deliverable
        snapshot = Snapshot.get_latest_by_sobject(prev_sobject, prev_process)
        if not snapshot:
            return

        # once we have this snapshot, open the file and process
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_name_by_type("maya")

        file_path = "%s/%s" % (lib_dir, file_name)

        f = open(file_path, 'r')
        lines = f.readlines()
        f.close()

        tmp_dir = Environment.get_tmp_dir()
        new_file_name = "whatever.new"
        new_file_path = "%s/%s" % (tmp_dir, new_file_name)

        f2 = open(new_file_path, 'wb')
        for i, line in enumerate(lines):
            line = "%s - %s" % (i, line)
            f2.write(line)
        f2.close()

        file_paths = [new_file_path]
        file_types = ['maya']

        from pyasm.checkin import FileCheckin
        checkin = FileCheckin.get(this_sobject,
                                  file_paths,
                                  file_types,
                                  context=this_process)
        checkin.execute()

        my.set_event_name("task/approved")
        my.set_process("preprocess")
        my.set_pipeline_code("turntable")
        my.sobjects = [render]

        # ???
        my.sobject = render

        my.set_as_approved()
示例#18
0
    def execute(my):
        print "EXECUTING sample command"

        # create the render
        render = SearchType.create("prod/render")
        render.set_parent(my.prev_command.sobject)
        render.set_value("pipeline_code", "turntable")
        render.commit()
        Task.add_initial_tasks(render)

        prev_sobject = my.prev_command.sobject
        prev_process = "model"
        this_sobject = my.prev_command.sobject
        this_process = "turntable"

        # get the deliverable
        snapshot = Snapshot.get_latest_by_sobject(prev_sobject, prev_process)
        if not snapshot:
            return

        # once we have this snapshot, open the file and process
        lib_dir = snapshot.get_lib_dir()
        file_name = snapshot.get_name_by_type("maya")

        file_path = "%s/%s" % (lib_dir, file_name)

        f = open( file_path, 'r')
        lines = f.readlines()
        f.close()

        tmp_dir = Environment.get_tmp_dir()
        new_file_name = "whatever.new"
        new_file_path = "%s/%s" % (tmp_dir, new_file_name)

        f2 = open( new_file_path, 'wb')
        for i, line in enumerate(lines):
            line = "%s - %s" % ( i,line)
            f2.write(line)
        f2.close()

        file_paths = [new_file_path]
        file_types = ['maya']

        from pyasm.checkin import FileCheckin
        checkin = FileCheckin.get(this_sobject, file_paths, file_types, context=this_process)
        checkin.execute()

        my.set_event_name("task/approved")
        my.set_process("preprocess")
        my.set_pipeline_code("turntable")
        my.sobjects = [render]

        # ???
        my.sobject = render


        my.set_as_approved()
示例#19
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()


        checkin = FileCheckin(self.person, file_path, context="sym_test", checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path =versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path)) 
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path  = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2], file_types=['add'], keep_file_name=False, checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(main_lib_path.endswith('/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), "sym_test", mode='latest', create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(lib_path.endswith('/sym_test/symlink_append_sym_test.txt'), True)
            self.assertEquals(os.path.exists(lib_path), True)
示例#20
0
    def _test_checkin(self):

        # create a new test.txt file
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(), file_name)
        self.assertEquals(True, os.path.exists(lib_path))
示例#21
0
    def _test_checkin(self):

        # create a new test.txt file
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(),file_name)
        self.assertEquals(True, os.path.exists(lib_path) )
示例#22
0
 def _check_in_swf(my, snapshot, sobject, render, pat, final_pat, render_dir, filenames):
     final_path = icon_path = ''
     for name in filenames:
         if pat.match(name):
             final_name = pat.sub(final_pat, name)
             shutil.move(render_dir + "/" + name, render_dir \
                 + "/" + final_name)
             src_path = "%s/%s" % (render_dir, final_name) 
             if final_name.endswith('.png'):
                 icon_creator = IconCreator(src_path)
                 icon_creator.create_icons()
                 icon_path = icon_creator.get_icon_path()
             elif final_name.endswith('.swf'):
                 final_path = src_path
     types = ["main"]
     paths = [final_path]
     
     if icon_path:
         paths.append(icon_path)
         types.append('icon')
     checkin = FileCheckin(render, paths, types, context="render", column="images")
     checkin.execute()
示例#23
0
    def _test_file_owner(self):
        # FIXME: this test has hard coded st_uids that only work on very
        # specific conditions
        return

        if os.name == 'nt':
            return
        # create a new test.txt file
        file_path = "./test2.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()
        # owned by root
        os.system('echo south123paw | sudo -S chown root.root \"%s\"' %
                  file_path)

        stat = os.stat(file_path)
        self.assertEquals(stat.st_uid, 0)

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(), file_name)
        self.assertEquals(True, os.path.exists(lib_path))
        stat = os.stat(lib_path)
        if Config.get_value("checkin", "sudo_no_password") == 'true':
            self.assertEquals(stat.st_uid, 48)
        else:
            # if not set, it will remain owned by root
            self.assertEquals(stat.st_uid, 0)
示例#24
0
    def check(my):
        web = WebContainer.get_web()
        if web.get_form_value(MayaShotCheckinWdg.PUBLISH_SET_BUTTON) == "":
            return False

        if not my._check_context():
            return False

        # if there is publish error, exit
        error_path = '%s/error.txt' % FileCheckin.get_upload_dir()
        if os.path.exists(error_path):
            return False

        return True
示例#25
0
    def check(my):
        web = WebContainer.get_web()
        if web.get_form_value(MayaShotCheckinWdg.PUBLISH_SET_BUTTON) == "":
            return False
         
        if not my._check_context():
            return False

        # if there is publish error, exit
        error_path = '%s/error.txt' %FileCheckin.get_upload_dir()
        if os.path.exists(error_path):
            return False

        return True
示例#26
0
    def _test_file_owner(self):
        # FIXME: this test has hard coded st_uids that only work on very
        # specific conditions
        return

        if os.name == 'nt':
            return
        # create a new test.txt file
        file_path = "./test2.txt"
        file = open(file_path, 'w')
        file.write("whatever")
        file.close()
        # owned by root
        os.system('echo south123paw | sudo -S chown root.root \"%s\"'%file_path)

        stat = os.stat(file_path)
        self.assertEquals(stat.st_uid, 0)

        checkin = FileCheckin(self.person, file_path, "test")
        checkin.execute()

        # check that the file exists
        snapshot = checkin.get_snapshot()
        xml = snapshot.get_xml_value("snapshot")
        file_code = xml.get_value("snapshot/file/@file_code")
        file_name = xml.get_value("snapshot/file/@name")

        self.assertNotEqual(None, file)

        lib_path = "%s/%s" % (snapshot.get_lib_dir(),file_name)
        self.assertEquals(True, os.path.exists(lib_path) )
        stat = os.stat(lib_path)
        if Config.get_value("checkin", "sudo_no_password") == 'true': 
            self.assertEquals(stat.st_uid, 48)
        else:
            # if not set, it will remain owned by root
            self.assertEquals(stat.st_uid, 0)
示例#27
0
    def setup(self):

        # create a dummy sobject
        sobject = SearchType.create("unittest/city")
        sobject.commit()

        # check in a file to the city
        file_path = "./test.txt"
        file = open(file_path, 'w')
        file.write("test test test")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(sobject,
                              file_paths=file_paths,
                              file_types=file_types,
                              context="test",
                              mode="move")
        checkin.execute()

        return sobject
示例#28
0
    def _test_copycheckin(self):

        # create a new copy_test.txt file
        file_path = "./copy_test.txt"
        file = open(file_path, 'w')
        file.write("copy contents")
        file.close()

        file_paths = [file_path]
        file_types = ['main']
        context = "publish"
        from pyasm.checkin import FileCheckin
        checkin = FileCheckin(self.person,
                              file_paths=file_paths,
                              file_types=file_types,
                              context=context,
                              mode="copy")
        checkin.execute()
        self.assertEquals(True, os.path.exists(file_path))

        snap = checkin.get_snapshot()
        file_obj = snap.get_file_by_type('main')
        file_name = file_obj.get_file_name()
        self.assertEquals(file_name, 'copy_test_publish_v002.txt')
示例#29
0
    def _parse_form(my):
 
        # get the downloaded files and sort them
        web = WebContainer.get_web()
        
        my.upload_values.sort()

        filenames = []
        ticket = web.get_cookie("login_ticket")
        # create a new entry for every file
        for upload_value in my.upload_values:
            tmp_dir = Environment.get_tmp_dir()
            basename = os.path.basename(upload_value)
            file_path = "%s/upload/%s/%s" % (tmp_dir, ticket, basename)

            filenames.append(basename)

            creator = IconCreator(file_path)
            creator.create_icons()

            my.file_paths = [file_path]
            file_types = ["main"]

            web_path = creator.get_web_path()
            if web_path != None:
                my.file_paths.append(web_path)
                file_types.append("web")

            icon_path = creator.get_icon_path()
            if icon_path != None:
                my.file_paths.append(icon_path)
                file_types.append("icon")

            sobject = None
            if my.search_key:
                sobject = Search.get_by_search_key(my.search_key)
            else:    
                sobject = SObjectFactory.create(my.search_type)
                sobject.commit()

            checkin = FileCheckin( sobject, my.file_paths, file_types,\
                column=my.column )
             
            checkin.set_description(web.get_form_value(SObjectUploadCmd.PUBLISH_COMMENT))
            checkin.execute()
            my.repo_file_list.append(checkin.file_dict)
            

        
        my.description = "Added files: %s" % filenames
示例#30
0
    def postprocess(self):
        web = get_web_container()
        self.files = []
        self.file_types = []
        if self.get_option('upload_type') == 'arbitrary':
            self._upload_arbitrary_files()
        else:
            self._upload_specified_files()

        context = self.get_value("%s|context" % self.name)
        subcontext = self.get_value("%s|subcontext" % self.name)
        if subcontext:
            context = '%s/%s' %(context, subcontext)
        description = self.get_value("%s|description" % self.name)
        from pyasm.widget import CheckboxWdg
        cb = CheckboxWdg("%s|is_revision" % self.get_input_name())
        is_rev = cb.is_checked(False)
        
        # let checkin take care of moving files to the lib
        from pyasm.checkin import FileCheckin
        self.checkin = FileCheckin.get( self.sobject, self.files, self.file_types,  \
            context=context, snapshot_type="file" )
        self.checkin.set_description(description)
        self.checkin.set_revision(is_rev)
        self.checkin.execute()


        self.sobjects.append(self.sobject)
        self.info['context'] = context
        self.add_description('File Publish for [%s]' %self.sobject.get_code())
        # remove the files in upload area
        for file in self.files:
            if os.path.exists(file):
                os.unlink(file)

        Trigger.call(self, "email")
示例#31
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '',
            '',  # do 2 checkins
            'hi',
            'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            versionless_current = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='current',
                create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')

            else:
                self.assertEquals(None, versionless_current)

            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
示例#32
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '',
            '',  # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #import time
            #start = time.time()

            checkin = FileCheckin(self.person,
                                  file_path,
                                  context=context,
                                  checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"

            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context"))
            if i != 1:  # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version"))
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version"))

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (
                    person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin",
                                         "asset_base_dir",
                                         sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)

            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)

            exists = os.path.exists(path)
            self.assertEquals(True, exists)

            # check that a versionless has been created
            versionless = Snapshot.get_versionless(
                self.person.get_search_type(),
                self.person.get_id(),
                context,
                mode='latest',
                create=False)

            self.assertNotEquals(None, versionless)

            self.assertEquals(-1, versionless.get_value("version"))

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)
示例#33
0
    def _test_snapshot(my):

        # create a new test.txt file
        for i in range(0, 4):

            # create a new test.txt file
            my.file_path = "./biz_test.txt"
            for i in range(0, 4):
                file = open(my.file_path, 'w')
                file.write("whatever")
                file.close()

            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context)
            checkin.execute()

            # get snapshot from database
            snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()

        # get version -1
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_id,
                                           context=my.context,
                                           version=-1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)

        # latest version
        snapshot = Snapshot.get_latest(my.search_type,
                                       my.search_id,
                                       context=my.context,
                                       use_cache=False)
        version = snapshot.get_version()

        my.assertEquals('biz_test_test_v004.txt',
                        snapshot.get_all_file_names()[0])
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        for i in range(0, 2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
            # check in 2 current revisions
            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context,
                                  is_revision=True,
                                  is_current=True)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            # get snapshot from database
            #snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()

        # get current version and revision latest
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_code,
                                           context=my.context,
                                           version=0,
                                           revision=-1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)

        # get revision
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)

        # v4r1 should not be latest
        snapshot = Snapshot.get_by_version(my.search_type,
                                           my.search_id,
                                           context=my.context,
                                           version=4,
                                           revision=1,
                                           use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(1, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # is_latest is v4r2, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=None,
                                         use_cache=False)

        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version='max',
                                         revision=None,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        # add 2 non current revisions
        for i in range(0, 2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 revisions
            checkin = FileCheckin(my.person,
                                  my.file_path,
                                  "main",
                                  context=my.context,
                                  is_revision=True,
                                  is_current=False)
            checkin.execute()

        # get latest version and revision
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(4, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)

        # get current version and latest revision (but current v4r2 takes precedence)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=0,
                                         revision=-1,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # get current version and 0 revision (but current v4r2 is the real current, returns None)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=0,
                                         revision=None,
                                         use_cache=False)
        my.assertEquals(None, snapshot)

        # is_latest is v4r4, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version=-1,
                                         revision=None,
                                         use_cache=False)
        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         context=my.context,
                                         version='max',
                                         revision=None,
                                         use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        # create a new test.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        # check in another revision v4r5
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context,
                              is_revision=True,
                              is_current=False)
        checkin.execute()
        my.assertEquals(4, checkin.snapshot.get_version())
        my.assertEquals(5, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # check in new revision v101 with a new context
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context='rev_test',
                              is_revision=True,
                              is_current=False)
        checkin.execute()
        my.assertEquals(1, checkin.snapshot.get_version())
        my.assertEquals(1, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context='rev_test',
                              is_revision=False,
                              is_current=False)
        checkin.execute()
        # this should increment to v2r1
        my.assertEquals(2, checkin.snapshot.get_version())
示例#34
0
    def get_display(my):

        my.doc_mode = my.kwargs.get("doc_mode")
        path = my.kwargs.get("path")
        my.search_type = my.kwargs.get("search_type")

        my.last_path = None

        doc_key = my.kwargs.get("doc_key")
        if doc_key:
            my.doc = Search.get_by_search_key(doc_key)
            snapshot = Snapshot.get_latest_by_sobject(my.doc)
            if snapshot:
                my.last_path = snapshot.get_lib_path_by_type('main')

            path = my.doc.get_value("link")

        # TEST TEST TEST
        if not path:
            #path = "/home/apache/pdf/mongodb.txt"
            #path = "/home/apache/assets/google_docs.html"
            #path = "/home/apache/pdf/star_wars.txt"
            path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true"

            path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub"

            #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html"
            path = "/home/apache/tactic/doc/alias.json"

        if not my.search_type:
            my.search_type = "test3/shot"

        my.column = "description"

        top = my.top
        top.add_class("spt_document_top")
        my.set_as_panel(top)

        #table = Table()
        table = ResizableTableWdg()

        top.add(table)
        table.add_row()
        table.set_max_width()

        left_td = table.add_cell()
        left_td.add_style("vertical-align: top")

        title = DivWdg()
        left_td.add(title)
        title.add_style("padding: 10px")
        title.add_color("background", "background3")

        button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        title.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })
        button.add_style("float: left")

        button = IconButtonWdg(title="Save", icon=IconWdg.SAVE)
        title.add(button)
        button.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            '''
        })
        button.add_style("float: left")

        if not my.doc_mode:
            my.doc_mode = "text"
        select = SelectWdg("doc_mode")
        select.set_option("values", "text|formatted")
        title.add(select)
        select.set_value(my.doc_mode)
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            var value = bvr.src_el.value;
            top.setAttribute("spt_doc_mode", value);
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })

        title.add("<br clear='all'/>")

        #title.add(path)

        text_wdg = DivWdg()
        text_wdg.add_class("spt_document_content")
        left_td.add(text_wdg)

        #if path.startswith("https://docs.google.com/spreadsheet"):
        #    #path = "http://www.southpawtech.com.com"
        #    text_wdg.add('''
        #    <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe>
        #    ''' % path)
        #    text_wdg.add_style("overflow-x: hidden")
        if True:

            if not my.last_path and my.doc:
                tmp_dir = Environment.get_tmp_dir()
                tmp_path = '%s/last_path.txt' % tmp_dir
                f = open(tmp_path, 'w')

                text = my.get_text(path, highlight=False)

                f.write(text)
                f.close()

                cmd = FileCheckin(my.doc, tmp_path)
                Command.execute_cmd(cmd)

            else:
                save = False
                if save:
                    # open up the last path
                    f = open(my.last_path, 'r')
                    last_text = f.read()
                    text = my.get_text(path, None, highlight=False)

                    if last_text != text:

                        tmp_dir = Environment.get_tmp_dir()
                        tmp_path = '%s/last_path.txt' % tmp_dir
                        f = open(tmp_path, 'w')
                        f.write(text)
                        f.write(text)
                        f.close()

                        cmd = FileCheckin(my.doc, tmp_path)
                        Command.execute_cmd(cmd)

                text = my.get_text(path, my.last_path)

            lines = text.split("\n")

            if my.doc_mode == "text":

                num_lines = len(lines)
                """
                line_div = HtmlElement.pre()
                text_wdg.add(line_div)
                line_div.add_style("width: 20px")
                line_div.add_style("float: left")
                line_div.add_style("text-align: right")
                line_div.add_style("opacity: 0.3")
                line_div.add_style("padding-right: 10px")
                for i in range(0, num_lines*2):
                    line_div.add(i+1)
                    line_div.add("<br/>")
                """

            if my.doc_mode == "text":
                pre = HtmlElement.pre()
                pre.add_style("white-space: pre-wrap")
            else:
                pre = DivWdg()
            pre = DivWdg()
            text_wdg.add(pre)

            text_wdg.add_style("padding: 10px 5px")
            text_wdg.add_style("max-height: 600px")
            text_wdg.add_style("overflow-y: auto")
            text_wdg.add_style("width: 600px")
            text_wdg.add_class("spt_resizable")

            pre.add_style("font-family: courier")

            if my.doc_mode == "formatted":
                pre.add(text)

            else:
                line_table = Table()
                pre.add(line_table)
                line_table.add_style("width: 100%")
                count = 1
                for line in lines:
                    #line = line.replace(" ", "&nbsp;")
                    tr = line_table.add_row()
                    if count % 2 == 0:
                        tr.add_color("background", "background", -2)

                    td = line_table.add_cell()

                    # FIXME: hacky
                    if line.startswith('''<span style='background: #CFC'>'''):
                        is_new = True
                    else:
                        td.add_style("vertical-align: top")
                        text = TextWdg()
                        text.add_style("border", "none")
                        text.add_style("text-align", "right")
                        text.add_style("width", "25px")
                        text.add_style("margin", "0 10 0 0")
                        text.add_style("opacity", "0.5")
                        text.set_value(count)
                        td.add(text)
                        count += 1
                        is_new = False

                    td = line_table.add_cell()
                    if not is_new:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_CTX')
                        tr.add_class("spt_line")
                    else:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX')
                        tr.add_class("spt_new_line")

                    td.add_class("spt_line_content")
                    td.add(line)

            #from tactic.ui.app import AceEditorWdg
            #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px")
            #text_wdg.add(editor)

        # add a click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_document_top");
            var data_el = top.getElement(".spt_document_data");

            var search_key = bvr.src_el.getAttribute("spt_search_key");

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': bvr.search_type,
                'search_key': search_key,
            }
            spt.panel.load(data_el, class_name, kwargs);
            '''
        })

        # add a double click on spt_item
        bgcolor = text_wdg.get_color("background", -10)
        text_wdg.add_relay_behavior({
            'type':
            'mouseover',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'bgcolor':
            bgcolor,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "normal");
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
        })

        # add a double click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseout',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "bold");
            bvr.src_el.setStyle("background", "");
            '''
        })

        # add a context menu
        ctx_menu = my.get_text_context_menu()
        ctx_new_menu = my.get_text_new_context_menu()
        menus_in = {
            'TEXT_CTX': ctx_menu,
            'TEXT_NEW_CTX': ctx_new_menu,
        }
        SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False)

        panel = ViewPanelWdg(search_type=my.search_type, layout="blah")

        right_td = table.add_cell()
        right_td.add_style("vertical-align: top")

        panel_div = DivWdg()
        panel_div.add_class("spt_document_data")
        right_td.add(panel_div)
        panel_div.add(panel)

        text_wdg.add_behavior({
            'type':
            'load',
            'cbjs_action':
            r'''

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

    if (frame) {
        var rng = frame.contentWindow.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }

    else if (window.getSelection) // FF4 with one tab open?
    {
        var rng = window.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.getSelection) // FF4 with multiple tabs open?
    {
        var rng = document.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.selection) // IE8
    {
        var rng = document.selection.createRange();
        // expand range to enclose any word partially enclosed in it
        rng.expand("word");
        t = rng.text;
    }

    // convert newline chars to spaces, collapse whitespace, and trim non-word chars
    return t.replace(/^\W+|\W+$/g, '');
    //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, '');
}

// expand FF range to enclose any word partially enclosed in it
spt.document.expandtoword = function(range)
{
    if (range.collapsed) {
        return;
    }

    while (range.startOffset > 0 && range.toString()[0].match(/\w/)) {
        range.setStart(range.startContainer, range.startOffset - 1);
    }

    while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/))
    {
        range.setEnd(range.endContainer, range.endOffset + 1);
    }
}
            '''
        })

        top.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_content',
            'cbjs_action':
            r'''
            //spt.ace_editor.set_editor_top(bvr.src_el);
            //var text = spt.ace_editor.get_selection();
            var text = spt.document.get_selected_text();
            text = text.replace(/\n\n/mg, "\n");
            text = text.replace(/\n\n/mg, "\n");
            spt.document.selected_text = text + "";
            '''
        })

        return top
示例#35
0
    def _test_checkin_type(my):
        my.assertEquals(my.auto_snapshot.get_version(), 2)
        dir_name = my.auto_snapshot.get_file_name_by_type('main')
        my.assertEquals(dir_name , 'naming_test_folder_naming_base_test_v002')
        
        dir_name = my.auto_snapshot2.get_file_name_by_type('main')

        my.assertEquals(1, my.auto_snapshot2.get_version())
        my.assertEquals(dir_name , '.tactic_test_naming_folder_test_v001')

        dir_name = my.auto_snapshot3.get_file_name_by_type('main')
        # this takes the auto generated name
        my.assertEquals(dir_name , 'naming_test_folder3_naming_base_test_v003')


        # this one would take into account of the new naming entry introduced in _test_get_naming
        # test a blank checkin_type
        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='', mode='copy')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v004')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        snapshot_xml = my.auto_snapshot4.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        # un-specified checkin_type with a matching naming will default to "strict"
        my.assertEquals('strict', checkin_type[0])

        # this should pick the auto checkin_type naming convention with the _OO at the end of context
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test_OO', snapshot_type='directory', checkin_type='', mode='copy')
        checkin.execute()
        my.auto_snapshot4 = checkin.get_snapshot()
        dir_name = my.auto_snapshot4.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot4.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v001')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        snapshot_xml = my.auto_snapshot4.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        # un-specified checkin_type with a matching naming will default to "strict"
        my.assertEquals('auto', checkin_type[0])


        dir_path4 = "./naming_test_folder4"
        checkin = FileCheckin(my.person, dir_path4, "main", context='naming_base_test', snapshot_type='directory', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot5 = checkin.get_snapshot()
        snapshot_xml = my.auto_snapshot5.get_xml_value('snapshot')
        checkin_type = snapshot_xml.get_nodes_attr('/snapshot','checkin_type')
        
        dir_name = my.auto_snapshot5.get_file_name_by_type('main')
        lib_dir = my.auto_snapshot5.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil_v005')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        my.assertEquals('auto', checkin_type[0])

        versionless = Snapshot.get_versionless(my.auto_snapshot5.get_value('search_type'), my.auto_snapshot5.get_value('search_id'), 'naming_base_test', mode='latest', create=False)

        dir_name = versionless.get_file_name_by_type('main')
        lib_dir = versionless.get_dir('relative')
        my.assertEquals(dir_name , 'generic_phil')
        my.assertEquals(lib_dir , 'unittest/cut/generic/phil')
        path = versionless.get_lib_path_by_type()
示例#36
0
    def create_snapshot(my):
        # set up a real person and snapshot (as opposed to virtual)
        code = 'phil'
       
        my.person = SearchType.create( 'unittest/person' )
        my.person.set_value("code",code)
        my.person.set_value("name_first", "Philip")
        my.person.commit()


        # create a new test.txt file
        file_path = "./naming_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()

        # create another test_base.txt file
        file_path = "./naming_base_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_base_test')
        checkin.execute()
        my.base_snapshot = checkin.get_snapshot()

        dir_path = "./naming_test_folder"
        dir_path2 = "./.tactic_test" # test . folder
        dir_path3 = "./naming_test_folder3"
        dir_path4 = "./naming_test_folder4"
        for path in [dir_path, dir_path2, dir_path3, dir_path4]:
            if not os.path.exists(path):
                os.makedirs(path)

        checkin = FileCheckin(my.person, dir_path, "main", context='naming_base_test', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot = checkin.get_snapshot()
        checkin = FileCheckin(my.person, dir_path2, "main", context='naming_folder_test', snapshot_type='directory', checkin_type='auto')
        checkin.execute()
        my.auto_snapshot2 = checkin.get_snapshot()

        # test a blank checkin_type
        checkin = FileCheckin(my.person, dir_path3, "main", context='naming_base_test', snapshot_type='directory', checkin_type='')
        checkin.execute()
        my.auto_snapshot3 = checkin.get_snapshot()
示例#37
0
    def _test_notification(self):
        
        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 001: a new item has been added.')
        sobject.set_value("event",'insert|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 002: an item has been updated.')
        sobject.set_value("event",'update|unittest/country')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 003: New notes added.')
        sobject.set_value("event",'insert|sthpw/note')
        sobject.commit()      

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 004: New task assigned.')
        sobject.set_value("event",'change|sthpw/task|status')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 005: task status has been changed.')
        sobject.set_value("event",'change|sthpw/task|assigned')
        sobject.commit()

        sobject = SearchType.create("sthpw/notification")
        sobject.set_value('subject', 'TACTIC Unittest 006: Files are checked in.')
        sobject.set_value("event",'checkin|unittest/country')
        sobject.commit()

        # Item added
        self.clear_notification()
        sobject1 = SearchType.create("unittest/country")
        sobject1.set_value('code', 'test_update_trigger')
        sobject1.commit()

        # Updated item
        sobject1.set_value('code','success') 
        sobject1.commit()  

        # Note added
        Note.create(self.person, "test note2", context='default2')

        # Task assigned
        sobject = Task.create(self.person,'hi','hellotest',assigned="test assigned")

        # Task status changed
        tasks = Task.get_by_sobject(self.person)
        tasks[0].set_value('process','success')
        tasks[0].commit()

        # Files are checked in
        file_path = "./notification_test_check.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(sobject1, file_path, "main", context='test', checkin_type='auto')
        checkin.execute()
        Trigger.call_all_triggers()

        if os.path.exists(file_path):
            os.remove(file_path)
示例#38
0
文件: biz_test.py 项目: funic/TACTIC
    def _test_level(my):

        # add a country
        sobject = SearchType.create("unittest/country")
        sobject.set_value("code", "canada")
        sobject.commit()


        # add a city
        sobject = SearchType.create("unittest/city")
        sobject.set_value("code", "toronto")
        sobject.set_value("country_code", "canada")
        sobject.commit()

        my.person.set_value("city_code", "toronto")
        my.person.commit()
        

        level_type = "unittest/city"
        level_code = "toronto"
        level = Search.get_by_code(level_type, level_code)
        level_id = level.get_id()


        # create a new test.txt file
        my.file_path = "./biz_test.txt"
        for i in range(0,4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
       
        # creating version 5
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context)
        checkin.execute()
        
        my.file_path = "./biz_fulltest.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # for checkin using test/subtest
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.full_context)
        checkin.execute()


        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, my.context, version=-1, use_cache=True, level_type=level_type, level_id=level_id)
        # make sure we get the top level one
        my.assertEquals( 5, snapshot.get_value("version") )
        my.assertEquals( "", snapshot.get_value("level_type") )
        # integer None is now converted to 0
        my.assertEquals( 0, snapshot.get_value("level_id") )


        # checkin the file to the level
        my.file_path = "./biz_test_level.txt"
        for i in range(0,4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, level_type=level_type, level_id=level_id)
        checkin.execute()

        snapshot = checkin.get_snapshot()
        version = snapshot.get_version()
        my.assertEquals(1, version)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, my.context, version='-1', use_cache=True, level_type=level_type, level_id=level_id)

        my.assertEquals( level_type, snapshot.get_value("level_type") )
        my.assertEquals( level_id, snapshot.get_value("level_id") )
        my.assertEquals( 1, snapshot.get_value("version") )
        my.assertEquals( True, snapshot.get_value("is_latest") )
        my.assertEquals( True, snapshot.get_value("is_current") )


        # get latest version and revision of the person and make sure 
        # it has its own is_latest
        top_snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = top_snapshot.get_version()
        my.assertEquals(5, version)
        revision = top_snapshot.get_value('revision')
        my.assertEquals(0, revision)
        my.assertEquals( True, top_snapshot.get_value("is_latest") )
        my.assertEquals( True, top_snapshot.get_value("is_current") )
示例#39
0
文件: biz_test.py 项目: funic/TACTIC
    def _test_snapshot(my):


        # create a new test.txt file
        for i in range(0,4):

            # create a new test.txt file
            my.file_path = "./biz_test.txt"
            for i in range(0,4):
                file = open(my.file_path, 'w')
                file.write("whatever")
                file.close()

            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context)
            checkin.execute()

            # get snapshot from database
            snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()


        # get version -1
        snapshot = Snapshot.get_by_version(my.search_type, my.search_id, context=my.context, version=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)

        # latest version
        snapshot = Snapshot.get_latest(my.search_type, my.search_id, context=my.context, use_cache=False)
        version = snapshot.get_version()

        my.assertEquals('biz_test_test_v004.txt', snapshot.get_all_file_names()[0])
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        for i in range(0,2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 current revisions
            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=True)
            checkin.execute()
            snapshot = checkin.get_snapshot()

            # get snapshot from database
            #snapshot = checkin.get_snapshot()
            code = snapshot.get_value("code")
            s = Search("sthpw/snapshot")
            s.add_filter("code", code)
            snapshot = s.get_sobject()


        # get current version and revision latest
        snapshot = Snapshot.get_by_version(my.search_type, my.search_code, context=my.context, version=0, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
            
        # get revision
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)
        
        # v4r1 should not be latest
        snapshot = Snapshot.get_by_version(my.search_type, my.search_id, context=my.context, version=4, revision=1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(1, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)

        # is_latest is v4r2, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=None, use_cache=False)
        
        my.assertEquals(None, snapshot)

        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version='max', revision=None, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)
    
        # add 2 non current revisions
        for i in range(0,2):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

            # check in 2 revisions
            checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=False)
            checkin.execute()


        # get latest version and revision
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(4, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(True, is_latest)


        # get current version and latest revision (but current v4r2 takes precedence)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=0, revision=-1, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(2, revision)
        is_latest = snapshot.get_value('is_latest')
        my.assertEquals(False, is_latest)


        # get current version and 0 revision (but current v4r2 is the real current, returns None)
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=0, revision=None, use_cache=False)
        my.assertEquals(None, snapshot)

        
        # is_latest is v4r4, so can't find v4r0 any more
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version=-1, revision=None, use_cache=False)
        my.assertEquals(None, snapshot)
        
        
        # use max to find v4r0
        snapshot = Snapshot.get_snapshot(my.search_type, my.search_id, context=my.context, version='max', revision=None, use_cache=False)
        version = snapshot.get_version()
        my.assertEquals(4, version)
        revision = snapshot.get_value('revision')
        my.assertEquals(0, revision)

        
        # create a new test.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        # check in another revision v4r5 
        checkin = FileCheckin(my.person, my.file_path, "main", context=my.context, is_revision=True, is_current=False)
        checkin.execute()
        my.assertEquals(4, checkin.snapshot.get_version())
        my.assertEquals(5, checkin.snapshot.get_value('revision'))
                
        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # check in new revision v101 with a new context
        checkin = FileCheckin(my.person, my.file_path, "main", context='rev_test', is_revision=True, is_current=False)
        checkin.execute()
        my.assertEquals(1, checkin.snapshot.get_version())
        my.assertEquals(1, checkin.snapshot.get_value('revision'))

        # create a new test_version.txt file
        my.file_path = "./biz_test_version.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(my.person, my.file_path, "main", context='rev_test', is_revision=False, is_current=False)
        checkin.execute()
        # this should increment to v2r1
        my.assertEquals(2, checkin.snapshot.get_version())
示例#40
0
                    icon_path = creator.get_icon_path()
                    my.file_paths.append(icon_path)
                    file_types.append("icon")

                    web_path = creator.get_web_path()
                    my.file_paths.append(web_path)
                    file_types.append("web")


        # checkin all of the files into the sobjects
        if my._is_flash(search_type_obj):
            snapshot_type = "flash"
        else:
            snapshot_type = "file"

        checkin = FileCheckin( sobject, my.file_paths, file_types,
            column=my.column, snapshot_type=snapshot_type )
        # handle the description
        web = WebContainer.get_web()

        comment = web.get_form_value(my.PUBLISH_COMMENT)
        my.add_description('[%s] %s ' %(sobject.get_code(), comment))
        checkin.set_description(comment)
        
        
        checkin.execute()
        checkin_info = []
        for key, value in checkin.file_dict.items():
            if not my.get_response_list(): 
                checkin_info.append("'%s=%s'" %(key, value))
            else:
                for type in my.get_response_list():
示例#41
0
    def postprocess(my):
        web = get_web_container()

        keys = web.get_form_keys()

        from pyasm.search import Transaction
        transaction = Transaction.get()
        assert transaction

        # first get some data based in
        column = my.get_value("%s|column" % my.name)
        if column == "":
            column = my.name
       
        # NOTE: why did this change?
        #prefix = my.get_input_name()
        prefix = my.get_name()
        
        
        context = my.get_value("%s|context" % prefix)
        description = my.get_value("%s|description" % prefix)
        
        field_storage = my.get_value(prefix)
        handoff_path = my.get_value("%s|path" % prefix )
        custom_ticket = my.get_value("%s|ticket" % prefix )

        from pyasm.widget import CheckboxWdg
        cb = CheckboxWdg("%s|is_revision" % prefix)
        is_rev = cb.is_checked()

        if handoff_path:
            handoff_path = handoff_path.replace("\\", "/")

            # This check causes issues.. Just assume it's in the upload location
            #if not os.path.exists(handoff_path):
            security = Environment.get_security()
            ticket = security.get_ticket_key()

            # in case it's supplied by widget like SimpleUploadWdg
            if custom_ticket:
                ticket = custom_ticket

            handoff_path = os.path.basename(handoff_path)
            handoff_path = Common.get_filesystem_name(handoff_path)

            handoff_path = "%s/upload/%s/%s" % (Environment.get_tmp_dir(), ticket, handoff_path)


            print "Uploaded path: ", handoff_path
            if not os.path.exists(handoff_path):
                raise Exception("Uploaded Path [%s] does not exist" % handoff_path)

            my.files = [handoff_path]
            file_types = ['main']

            # create an icon
            icon_creator = IconCreator(handoff_path)
            icon_creator.execute()
            icon_path = icon_creator.get_web_path()
            if icon_path:
                my.files.append(icon_path)
                file_types.append("icon")
            web_path = icon_creator.get_icon_path()
            if web_path:
                my.files.append(web_path)
                file_types.append("web")


        elif field_storage != "":
        #else:
            # process and get the uploaded files
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.execute()

            # get files and file types
            my.files = upload.get_files()
            if not my.files:
                return
            file_types = upload.get_file_types()
        else:
            if my.get_option("file_required") == "true":
                err_msg = _("upload is required")
                raise TacticException("%s %s" % (my.name, err_msg))
            else:
                return


        checkin_class = my.get_option("checkin")
        if checkin_class:
            snapshot_type = my.get_option("snapshot_type")
            my.checkin = Common.create_from_class_path(checkin_class, [my.sobject, my.files, file_types, context, snapshot_type])

        else:
            from pyasm.checkin import FileCheckin
            my.checkin = FileCheckin.get( my.sobject, my.files, file_types,  \
                context=context, column=column, snapshot_type="file" )

        my.sobjects.append(my.sobject)

        my.checkin.set_description(description)
        my.checkin.set_revision(is_rev)
        my.checkin.execute()

        # remove the files in upload area
        for file in my.files:
            if os.path.exists(file):
                os.unlink(file)
示例#42
0
    def _test_with_naming(self):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "naming"

        subdirs = ['']

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/*")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.commit()

        # create 2nd naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/empty_dir_test")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.commit()

        # create 3rd latest_versionless naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/low")
        naming.set_value("file_naming", "{basefile}_latest.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("latest_versionless", "1")
        naming.commit()

        # create 4th current_versionless naming where
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/hi")
        naming.set_value("file_naming", "{basefile}_current.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("current_versionless", "1")
        naming.commit()

        self.clear_naming()

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin = FileCheckin(self.person, file_path, context=context)
            checkin.execute()

            # ensure that the check-in type is strict
            checkin_type = checkin.get_checkin_type()
            self.assertEquals("strict", checkin_type)

            snapshot = checkin.get_snapshot()

            checked_context = snapshot.get_value("context")

            path = snapshot.get_path_by_type("main")
            basename = os.path.basename(path)
            expected = "TESTfilename_v001.jpg"
            self.assertEquals(expected, basename)

        # create a new test.txt file
        file_path = "./%s" % filename
        file = open(file_path, 'w')
        file.write("test2")
        file.close()
        checkin = FileCheckin(self.person,
                              file_path,
                              context='naming/empty_dir_test')
        checkin.execute()
示例#43
0
    def execute(self):

        project_code = self.kwargs.get('project_code')
        project_title = self.kwargs.get('project_title')
        project_type = self.kwargs.get('project_type')
        project_description = self.kwargs.get("description")
        if not project_type:
            project_type = "simple"

        is_template = self.kwargs.get('is_template')
        project_theme = self.kwargs.get('project_theme')

        use_default_side_bar = self.kwargs.get('use_default_side_bar')
        if use_default_side_bar in [False, 'false']:
            use_default_side_bar = False
        else:
            use_default_side_bar = True


        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = 'default'
                    
                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")

                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")


        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        if project_description:
            project.set_value("description", project_description)
        # set the update of the database to current (this is obsolete)
        #project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ['true', True, 'True']:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)


        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)


        project.commit()
       
 

        # if there is an image, check it in
        upload_path = self.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException("Cannot find upload image for project [%s]" % upload_path)
            file_type = 'main'

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator
            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, 'web', 'icon']

            from pyasm.checkin import FileCheckin
            checkin = FileCheckin(project, context='icon', file_paths=file_paths, file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type =='unittest':
            base_type = 'unittest'
        elif not base_type:
            base_type = 'simple'


        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        #database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == 'Oracle':
            raise TacticException("Creation of project is not supported. Please create manually")




        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception as e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code





        # import the appropriate schema with config first
        database.import_schema(db_resource, base_type)

        self.create_schema(project_code)

        # before we upgrade, we have to commit the transaction
        # This is because upgrade actually run as separate processes
        # so if not commit has been made, the tables from importing the
        # schema will not have existed yet
        DbContainer.commit_thread_sql()


        self.upgrade()

        # import the appropriate data
        database.import_default_data(db_resource, base_type)


        # import default links
        if use_default_side_bar:
            self.import_default_side_bar()


        # create specified stypes
        self.create_search_types()


        # create theme
        if project_theme:
            self.create_theme(project_theme)



        # set as main project
        is_main_project = self.kwargs.get("is_main_project")
        if is_main_project in [True,'true','on']:
            Config.set_value("install", "default_project", project_code)
            Config.save_config()
            Config.reload_config()

        # initiate the DbContainer
        DbContainer.get('sthpw')


        self.info['result'] = "Finished creating project [%s]."%project_code

        print "Done."
示例#44
0
    def execute(my):

        project_code = my.kwargs.get("project_code")
        project_title = my.kwargs.get("project_title")
        project_type = my.kwargs.get("project_type")
        if not project_type:
            project_type = "simple"

        is_template = my.kwargs.get("is_template")
        project_theme = my.kwargs.get("project_theme")

        use_default_side_bar = my.kwargs.get("use_default_side_bar")
        if use_default_side_bar in [False, "false"]:
            use_default_side_bar = False
        else:
            use_default_side_bar = True

        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = "default"

                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")
                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")

        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        # set the update of the database to current (this is obsolete)
        # project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ["true", True, "True"]:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)

        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)

        project.commit()

        # if there is an image, check it in
        upload_path = my.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException("Cannot find upload image for project [%s]" % upload_path)
            file_type = "main"

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator

            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, "web", "icon"]

            from pyasm.checkin import FileCheckin

            checkin = FileCheckin(project, context="icon", file_paths=file_paths, file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type == "unittest":
            base_type = "unittest"
        elif not base_type:
            base_type = "simple"

        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        # database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == "Oracle":
            raise TacticException("Creation of project is not supported. Please create manually")

        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception, e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code
示例#45
0
    def _test_file_naming_manual_version(my):
       
        my.clear_naming()

        naming = SearchType.create('config/naming')
        naming.set_value('search_type','unittest/person')
        naming.set_value('context', 'naming_test')
        naming.set_value('dir_naming', '{project.code}/cut/{sobject.code}')
        naming.set_value('file_naming', '{sobject.code}_v{snapshot.version}.{ext}')
        naming.commit()

        from pyasm.common import Environment
        base_dir = Environment.get_asset_dir()
        
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_v005.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v001.ma'%base_dir, preallocated)

        # now turn on manual_version
        naming.set_value('manual_version', True)
        naming.commit()

        my.clear_naming()
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_v005.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v005.ma'%base_dir, preallocated)
        
        # Uppercase V and more digits
        preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what_V0010.ma',ext='ma')
        my.assertEquals('%s/unittest/cut/phil/phil_v010.ma'%base_dir, preallocated)
        #my.snapshot.commit()

        # zero or negative version is ignored
        # create a new manual version test.txt file
        file_path = "./naming_v0000_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(11, my.snapshot.get_version())

        # zero or negative version is ignored
        # create a new manual version test.txt file
        file_path = "./naming_v-23_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(12, my.snapshot.get_version())
        file_path = "./naming_v025_test.txt"
        for i in range(0,4):
            file = open(file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person, file_path, "main", context='naming_test')
        checkin.execute()
        my.snapshot = checkin.get_snapshot()
        my.assertEquals(25, my.snapshot.get_version())


        naming.delete()

        my.clear_naming()
示例#46
0
    def execute(my):

        project_code = my.kwargs.get('project_code')
        project_title = my.kwargs.get('project_title')
        project_type = my.kwargs.get('project_type')
        if not project_type:
            project_type = "simple"

        is_template = my.kwargs.get('is_template')
        project_theme = my.kwargs.get('project_theme')

        use_default_side_bar = my.kwargs.get('use_default_side_bar')
        if use_default_side_bar in [False, 'false']:
            use_default_side_bar = False
        else:
            use_default_side_bar = True

        assert project_code
        assert project_type
        if project_type:
            # check to see if it exists
            search = Search("sthpw/project_type")
            search.add_filter("code", project_type)
            project_type_sobj = search.get_sobject()
            if not project_type_sobj:

                # just create a default one in this case if it is named
                # after the project code
                if not is_template and project_type == project_code:
                    project_type = 'default'

                # create a new project type
                search = Search("sthpw/project_type")
                search.add_filter("code", project_type)
                project_type_sobj = search.get_sobject()
                if not project_type_sobj:
                    project_type_sobj = SearchType.create("sthpw/project_type")
                    project_type_sobj.set_value("code", project_type)
                    project_type_sobj.set_value("type", "simple")
                    project_type_sobj.commit()

        # set the current project to Admin
        Project.set_project("admin")

        # create a new project sobject
        project = SearchType.create("sthpw/project")
        project.set_value("code", project_code)
        project.set_value("title", project_title)
        project.set_value("type", project_type)
        # set the update of the database to current (this is obsolete)
        #project.set_value("last_db_update", "now()")
        project.set_value("last_version_update", "2.5.0.v01")

        if is_template in ['true', True, 'True']:
            project.set_value("is_template", True)
        else:
            project.set_value("is_template", False)

        if project_type != "default":
            category = Common.get_display_title(project_type)
            project.set_value("category", category)

        project.commit()

        # if there is an image, check it in
        upload_path = my.kwargs.get("project_image_path")
        if upload_path:
            if not os.path.exists(upload_path):
                raise TacticException(
                    "Cannot find upload image for project [%s]" % upload_path)
            file_type = 'main'

            file_paths = [upload_path]
            file_types = [file_type]

            source_paths = [upload_path]
            from pyasm.biz import IconCreator
            if os.path.isfile(upload_path):
                icon_creator = IconCreator(upload_path)
                icon_creator.execute()

                web_path = icon_creator.get_web_path()
                icon_path = icon_creator.get_icon_path()
                if web_path:
                    file_paths = [upload_path, web_path, icon_path]
                    file_types = [file_type, 'web', 'icon']

            from pyasm.checkin import FileCheckin
            checkin = FileCheckin(project,
                                  context='icon',
                                  file_paths=file_paths,
                                  file_types=file_types)
            checkin.execute()

        # find project's base_type
        base_type = project.get_base_type()

        if not base_type and project_type == 'unittest':
            base_type = 'unittest'
        elif not base_type:
            base_type = 'simple'

        # get the database for this project
        db_resource = project.get_project_db_resource()

        database = db_resource.get_database_impl()
        #database = DatabaseImpl.get()
        database_type = database.get_database_type()
        if database_type == 'Oracle':
            raise TacticException(
                "Creation of project is not supported. Please create manually")

        # creating project database
        print "Creating database '%s' ..." % project_code
        try:
            # create the datbase
            database.create_database(db_resource)
        except Exception, e:
            print str(e)
            print "WARNING: Error creating database [%s]" % project_code
示例#47
0
    def postprocess(self):
        web = get_web_container()

        keys = web.get_form_keys()

        from pyasm.search import Transaction
        transaction = Transaction.get()
        assert transaction

        # first get some data based in
        column = self.get_value("%s|column" % self.name)
        if column == "":
            column = self.name
       
        # NOTE: why did this change?
        #prefix = self.get_input_name()
        prefix = self.get_name()
        
        
        context = self.get_value("%s|context" % prefix)
        description = self.get_value("%s|description" % prefix)
        
        field_storage = self.get_value(prefix)
        handoff_path = self.get_value("%s|path" % prefix )
        custom_ticket = self.get_value("%s|ticket" % prefix )

        from pyasm.widget import CheckboxWdg
        cb = CheckboxWdg("%s|is_revision" % prefix)
        is_rev = cb.is_checked()

        if handoff_path:
            handoff_path = handoff_path.replace("\\", "/")

            # This check causes issues.. Just assume it's in the upload location
            #if not os.path.exists(handoff_path):
            security = Environment.get_security()
            ticket = security.get_ticket_key()

            # in case it's supplied by widget like SimpleUploadWdg
            if custom_ticket:
                ticket = custom_ticket

            handoff_path = os.path.basename(handoff_path)
            handoff_path = Common.get_filesystem_name(handoff_path)

            handoff_path = "%s/upload/%s/%s" % (Environment.get_tmp_dir(), ticket, handoff_path)


            print "Uploaded path: ", handoff_path
            if not os.path.exists(handoff_path):
                raise Exception("Uploaded Path [%s] does not exist" % handoff_path)

            self.files = [handoff_path]
            file_types = ['main']

            # create an icon
            icon_creator = IconCreator(handoff_path)
            icon_creator.execute()
            icon_path = icon_creator.get_web_path()
            if icon_path:
                self.files.append(icon_path)
                file_types.append("icon")
            web_path = icon_creator.get_icon_path()
            if web_path:
                self.files.append(web_path)
                file_types.append("web")


        elif field_storage != "":
        #else:
            # process and get the uploaded files
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.execute()

            # get files and file types
            self.files = upload.get_files()
            if not self.files:
                return
            file_types = upload.get_file_types()
        else:
            if self.get_option("file_required") == "true":
                err_msg = _("upload is required")
                raise TacticException("%s %s" % (self.name, err_msg))
            else:
                return


        checkin_class = self.get_option("checkin")
        if checkin_class:
            snapshot_type = self.get_option("snapshot_type")
            self.checkin = Common.create_from_class_path(checkin_class, [self.sobject, self.files, file_types, context, snapshot_type])

        else:
            from pyasm.checkin import FileCheckin
            self.checkin = FileCheckin.get( self.sobject, self.files, file_types,  \
                context=context, column=column, snapshot_type="file" )

        self.sobjects.append(self.sobject)

        self.checkin.set_description(description)
        self.checkin.set_revision(is_rev)
        self.checkin.execute()

        # remove the files in upload area
        for file in self.files:
            if os.path.exists(file):
                os.unlink(file)
示例#48
0
    def _test_strict_checkin(self):

        server = Config.get_value("install", "server")
        #process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "strict"

        subcontexts = [
            '', '', # do 2 checkins
            'hi', 'hi',
            'medium',
            'low',
        ]

        for i, subcontext in enumerate(subcontexts):

            if subcontext:
                context = "%s/%s" % (process, subcontext)
            else:
                context = process

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin.execute()
            snapshot = checkin.get_snapshot()
            #print "time: ", time.time() - start
            #print "---"

            # make sure there is no latest versionless except for process/low
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            versionless_current = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='current', create=False)

            if context == 'strict/low':
                self.assertNotEquals(None, versionless)
                file_objects = versionless.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name ,'filename_latest.jpg')
            else:
                self.assertEquals(None, versionless)

            # make sure there is no current versionless except for process/hi
            if context == 'strict/hi':
                self.assertNotEquals(None, versionless_current)
                file_objects = versionless_current.get_all_file_objects()
                self.assertEquals(1, len(file_objects))

                file_object = file_objects[0]
                relative_dir = file_object.get_value("relative_dir")
                file_name = file_object.get_value("file_name")
                self.assertEquals(file_name, 'filename_current.jpg')
                
            else:
                self.assertEquals(None, versionless_current)

            
            path = snapshot.get_path_by_type("main")

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")

            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))

            file_object = file_objects[0]
            relative_dir = file_object.get_value("relative_dir")
            file_name = file_object.get_value("file_name")

            test_path = "%s/%s/%s" % (asset_dir, relative_dir, file_name)
            self.assertEquals(test_path, path)
示例#49
0
    def _test_with_naming(self):

        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "naming"

        subdirs = ['']

        # create a naming
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/*")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.commit()

        # create 2nd naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "naming/empty_dir_test")
        naming.set_value("file_naming", "TEST{basefile}_v{version}.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.commit()

        # create 3rd latest_versionless naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/low")
        naming.set_value("file_naming", "{basefile}_latest.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("latest_versionless", "1")
        naming.commit()

        # create 4th current_versionless naming where 
        naming = SearchType.create("config/naming")
        naming.set_value("search_type", "unittest/person")
        naming.set_value("context", "strict/hi")
        naming.set_value("file_naming", "{basefile}_current.{ext}")
        naming.set_value("dir_naming", "{@GET(.description)}")
        naming.set_value("current_versionless", "1")
        naming.commit()

        self.clear_naming()


        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()

           
 


            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            #checkin = FileCheckin(self.person, file_path, context=context, checkin_type='strict')
            checkin = FileCheckin(self.person, file_path, context=context)
            checkin.execute()

            # ensure that the check-in type is strict
            checkin_type = checkin.get_checkin_type()
            self.assertEquals("strict", checkin_type)

            snapshot = checkin.get_snapshot()

            checked_context = snapshot.get_value("context")


            path = snapshot.get_path_by_type("main")
            basename = os.path.basename(path)
            expected = "TESTfilename_v001.jpg"
            self.assertEquals(expected, basename)


        # create a new test.txt file
        file_path = "./%s" % filename
        file = open(file_path, 'w')
        file.write("test2")
        file.close()
        checkin = FileCheckin(self.person, file_path, context='naming/empty_dir_test')
        checkin.execute()
示例#50
0
    def _test_symlink(self):
        if os.name == 'nt':
            return

        # create a new test.txt file
        file_path = "./symlink.txt"
        file = open(file_path, 'w')
        file.write("symlink test")
        file.close()

        file_path2 = "./symlink_append.txt"
        file = open(file_path2, 'w')
        file.write("append test")
        file.close()

        checkin = FileCheckin(self.person,
                              file_path,
                              context="sym_test",
                              checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        self.assertEquals(True, isinstance(versionless_snap, Snapshot))

        main_lib_path = snap.get_lib_path_by_type('main')
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_sym_test_v001.txt'), True)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('main')
            self.assertEquals(True, os.path.exists(lib_path))
            rel_path = os.readlink(lib_path)
            lib_dir = os.path.dirname(lib_path)

            # this is essentially handle_link() in FileUndo class
            wd = os.getcwd()
            os.chdir(lib_dir)
            real_path = os.path.join(lib_dir, os.path.abspath(rel_path))
            # lib_path points to real_path

            expected_rel_path = Common.relative_path(lib_path, real_path)
            self.assertEquals(True, os.path.exists(real_path))
            self.assertEquals(expected_rel_path, rel_path)
            os.chdir(wd)

        # if not inplace or preallocate mode, keep_file_name should be False
        checkin = FileAppendCheckin(snap.get_code(), [file_path2],
                                    file_types=['add'],
                                    keep_file_name=False,
                                    checkin_type='auto')
        checkin.execute()
        snap = checkin.get_snapshot()
        main_lib_path = snap.get_lib_path_by_type('add')
        self.assertEquals(snap.get_value('is_current'), True)
        self.assertEquals(snap.get_value('is_latest'), True)
        self.assertEquals(
            main_lib_path.endswith(
                '/sym_test/.versions/symlink_append_sym_test_v001.txt'), True)
        versionless_snap = Snapshot.get_versionless(
            self.person.get_search_type(),
            self.person.get_id(),
            "sym_test",
            mode='latest',
            create=False)
        if versionless_snap:
            lib_path = versionless_snap.get_lib_path_by_type('add')
            self.assertEquals(
                lib_path.endswith('/sym_test/symlink_append_sym_test.txt'),
                True)
            self.assertEquals(os.path.exists(lib_path), True)
示例#51
0
    def _test_inplace_checkin(self):

        # create a new test.txt file
        tmp_dir = Environment.get_tmp_dir()
        dir = "%s/temp" % tmp_dir
        if not os.path.exists(dir):
            os.makedirs(dir)
        file_path = "%s/test_inplace.txt" % dir

        if os.path.exists(file_path):
            os.unlink(file_path)

        file = open(file_path, 'w')
        file.write("whatever")
        file.close() 


        # inplace checkin: tell tactic that this is the correct path
        mode = "inplace"
        base_dir = tmp_dir
        context = "inplace"
        checkin = FileCheckin(self.person, file_path, context=context, mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        relative_dir = file_object.get_value("relative_dir")
        # The relative dir is empty if the file is outside the repository
        self.assertEquals("", relative_dir)

        lib_dir = snapshot.get_lib_dir(file_type="main")
        file_name = snapshot.get_file_name_by_type("main")
        lib_path = "%s/%s" % (lib_dir, file_name)
        self.assertEquals( True, os.path.exists(lib_path) )
        self.assertEquals( file_path, lib_path)




        # check in a file alredy in the repository
        asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")
        file_path2 = "%s/unittest/text.txt" % asset_dir

        file = open(file_path2, 'w')
        file.write("whatever")
        file.close() 

        checkin = FileCheckin(self.person, file_path2, context=context, mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        # check that the relative dir is as expected
        relative_dir = file_object.get_value("relative_dir")
        self.assertEquals( relative_dir, "unittest" )

        # check that the path returned correctly
        lib_path = snapshot.get_path_by_type("main")
        self.assertEquals( file_path2, lib_path )

        if os.path.exists(file_path):
            os.unlink(file_path)
        if os.path.exists(file_path2):
            os.unlink(file_path2)
示例#52
0
    def postprocess(my):
        sobject = my.sobject
        texture_snapshot = Snapshot.get_latest_by_sobject(sobject)
        web = WebContainer.get_web()

        source_search_key = web.get_form_value("predefined_source")
        if source_search_key and texture_snapshot:
            source = Search.get_by_search_key(source_search_key)
            source_snapshot = Snapshot.get_latest_by_sobject(source)
            
            xml = texture_snapshot.get_xml_value("snapshot")
            builder = SnapshotBuilder(xml)
            builder.add_ref_by_snapshot(source_snapshot)
            texture_snapshot.set_value("snapshot", builder.to_string() )
            texture_snapshot.commit()

            return




        # if no files have been uploaded, don't do anything
        field_storage = web.get_form_value("add_source")
        if field_storage == "":
            return

        # process and get the uploaded files
        upload = FileUpload()
        upload.set_field_storage(field_storage)
        upload.execute()
        files = upload.get_files()
        if not files:
            return

        file_types = upload.get_file_types()
        
        asset_code = sobject.get_value("asset_code")

        # checkin this as a new source
        import os
        source_code = os.path.basename(files[0])
        source_description = "Referred to %s" % my.sobject.get_code()
        source_category = "default"
        source = TextureSource.create(asset_code, source_code, \
            source_category, source_description)

        # add the file as a snapshot to this source
        checkin = FileCheckin(source, files, file_types )
        checkin.execute()

        source_snapshot = Snapshot.get_latest_by_sobject(source)
        xml = source_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_fref_by_snapshot(texture_snapshot)
        source_snapshot.set_value("snapshot", builder.to_string() )
        source_snapshot.commit()


        # Modify the snapshot in the original texture to reference this
        # source.  This assumes that the other uploaded snapshot has
        # already been dealt with.
        source_snapshot = checkin.get_snapshot()

        # FIXME: what if no texture was uploaded???
        xml = texture_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_ref_by_snapshot(source_snapshot)
        texture_snapshot.set_value("snapshot", builder.to_string() )
        texture_snapshot.commit()
示例#53
0
    def postprocess(self):
        sobject = self.sobject
        texture_snapshot = Snapshot.get_latest_by_sobject(sobject)
        web = WebContainer.get_web()

        source_search_key = web.get_form_value("predefined_source")
        if source_search_key and texture_snapshot:
            source = Search.get_by_search_key(source_search_key)
            source_snapshot = Snapshot.get_latest_by_sobject(source)

            xml = texture_snapshot.get_xml_value("snapshot")
            builder = SnapshotBuilder(xml)
            builder.add_ref_by_snapshot(source_snapshot)
            texture_snapshot.set_value("snapshot", builder.to_string())
            texture_snapshot.commit()

            return

        # if no files have been uploaded, don't do anything
        field_storage = web.get_form_value("add_source")
        if field_storage == "":
            return

        # process and get the uploaded files
        upload = FileUpload()
        upload.set_field_storage(field_storage)
        upload.execute()
        files = upload.get_files()
        if not files:
            return

        file_types = upload.get_file_types()

        asset_code = sobject.get_value("asset_code")

        # checkin this as a new source
        import os
        source_code = os.path.basename(files[0])
        source_description = "Referred to %s" % self.sobject.get_code()
        source_category = "default"
        source = TextureSource.create(asset_code, source_code, \
            source_category, source_description)

        # add the file as a snapshot to this source
        checkin = FileCheckin(source, files, file_types)
        checkin.execute()

        source_snapshot = Snapshot.get_latest_by_sobject(source)
        xml = source_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_fref_by_snapshot(texture_snapshot)
        source_snapshot.set_value("snapshot", builder.to_string())
        source_snapshot.commit()

        # Modify the snapshot in the original texture to reference this
        # source.  This assumes that the other uploaded snapshot has
        # already been dealt with.
        source_snapshot = checkin.get_snapshot()

        # FIXME: what if no texture was uploaded???
        xml = texture_snapshot.get_xml_value("snapshot")
        builder = SnapshotBuilder(xml)
        builder.add_ref_by_snapshot(source_snapshot)
        texture_snapshot.set_value("snapshot", builder.to_string())
        texture_snapshot.commit()
示例#54
0
    def _test_inplace_checkin(self):

        # create a new test.txt file
        tmp_dir = Environment.get_tmp_dir()
        dir = "%s/temp" % tmp_dir
        if not os.path.exists(dir):
            os.makedirs(dir)
        file_path = "%s/test_inplace.txt" % dir

        if os.path.exists(file_path):
            os.unlink(file_path)

        file = open(file_path, 'w')
        file.write("whatever")
        file.close()

        # inplace checkin: tell tactic that this is the correct path
        mode = "inplace"
        base_dir = tmp_dir
        context = "inplace"
        checkin = FileCheckin(self.person,
                              file_path,
                              context=context,
                              mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        relative_dir = file_object.get_value("relative_dir")
        # The relative dir is empty if the file is outside the repository
        self.assertEquals("", relative_dir)

        lib_dir = snapshot.get_lib_dir(file_type="main")
        file_name = snapshot.get_file_name_by_type("main")
        lib_path = "%s/%s" % (lib_dir, file_name)
        self.assertEquals(True, os.path.exists(lib_path))
        self.assertEquals(file_path, lib_path)

        # check in a file alredy in the repository
        asset_dir = Config.get_value("checkin",
                                     "asset_base_dir",
                                     sub_key="default")
        file_path2 = "%s/unittest/text.txt" % asset_dir

        file = open(file_path2, 'w')
        file.write("whatever")
        file.close()

        checkin = FileCheckin(self.person,
                              file_path2,
                              context=context,
                              mode=mode)
        checkin.execute()
        snapshot = checkin.get_snapshot()

        file_code = snapshot.get_file_code_by_type("main")
        file_object = File.get_by_code(file_code)

        # check that the relative dir is as expected
        relative_dir = file_object.get_value("relative_dir")
        self.assertEquals(relative_dir, "unittest")

        # check that the path returned correctly
        lib_path = snapshot.get_path_by_type("main")
        self.assertEquals(file_path2, lib_path)

        if os.path.exists(file_path):
            os.unlink(file_path)
        if os.path.exists(file_path2):
            os.unlink(file_path2)
示例#55
0
    def _test_level(my):

        # add a country
        sobject = SearchType.create("unittest/country")
        sobject.set_value("code", "canada")
        sobject.commit()

        # add a city
        sobject = SearchType.create("unittest/city")
        sobject.set_value("code", "toronto")
        sobject.set_value("country_code", "canada")
        sobject.commit()

        my.person.set_value("city_code", "toronto")
        my.person.commit()

        level_type = "unittest/city"
        level_code = "toronto"
        level = Search.get_by_code(level_type, level_code)
        level_id = level.get_id()

        # create a new test.txt file
        my.file_path = "./biz_test.txt"
        for i in range(0, 4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()

        # creating version 5
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context)
        checkin.execute()

        my.file_path = "./biz_fulltest.txt"
        file = open(my.file_path, 'w')
        file.write("whatever")
        file.close()
        # for checkin using test/subtest
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.full_context)
        checkin.execute()

        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         my.context,
                                         version=-1,
                                         use_cache=True,
                                         level_type=level_type,
                                         level_id=level_id)
        # make sure we get the top level one
        my.assertEquals(5, snapshot.get_value("version"))
        my.assertEquals("", snapshot.get_value("level_type"))
        # integer None is now converted to 0
        my.assertEquals(0, snapshot.get_value("level_id"))

        # checkin the file to the level
        my.file_path = "./biz_test_level.txt"
        for i in range(0, 4):
            file = open(my.file_path, 'w')
            file.write("whatever")
            file.close()
        checkin = FileCheckin(my.person,
                              my.file_path,
                              "main",
                              context=my.context,
                              level_type=level_type,
                              level_id=level_id)
        checkin.execute()

        snapshot = checkin.get_snapshot()
        version = snapshot.get_version()
        my.assertEquals(1, version)
        snapshot = Snapshot.get_snapshot(my.search_type,
                                         my.search_id,
                                         my.context,
                                         version='-1',
                                         use_cache=True,
                                         level_type=level_type,
                                         level_id=level_id)

        my.assertEquals(level_type, snapshot.get_value("level_type"))
        my.assertEquals(level_id, snapshot.get_value("level_id"))
        my.assertEquals(1, snapshot.get_value("version"))
        my.assertEquals(True, snapshot.get_value("is_latest"))
        my.assertEquals(True, snapshot.get_value("is_current"))

        # get latest version and revision of the person and make sure
        # it has its own is_latest
        top_snapshot = Snapshot.get_snapshot(my.search_type,
                                             my.search_id,
                                             context=my.context,
                                             version=-1,
                                             revision=-1,
                                             use_cache=False)
        version = top_snapshot.get_version()
        my.assertEquals(5, version)
        revision = top_snapshot.get_value('revision')
        my.assertEquals(0, revision)
        my.assertEquals(True, top_snapshot.get_value("is_latest"))
        my.assertEquals(True, top_snapshot.get_value("is_current"))
示例#56
0
    def _test_auto_checkin(self):
        server = Config.get_value("install", "server")
        process = "process"
        person_code = self.person.get_code()

        filename = "filename.jpg"

        process = "process"

        subdirs = [
            '', '', # do 2 checkins
            'subdir',
            'subdir/subsubdir'
        ]

        for i, subdir in enumerate(subdirs):

            if subdir:
                context = "%s/%s/%s" % (process, subdir, filename)
            else:
                context = "%s/%s" % (process, filename)

            # create a new test.txt file
            file_path = "./%s" % filename
            file = open(file_path, 'w')
            file.write("test")
            file.close()


            #import time
            #start = time.time()

            checkin = FileCheckin(self.person, file_path, context=context, checkin_type='auto')
            checkin.execute()

            #print "time: ", time.time() - start
            #print "---"


            # check the returned snapshot
            snapshot = checkin.get_snapshot()
            self.assertEquals(context, snapshot.get_value("context") )
            if i != 1: # the second checkin is version 2
                version = 1
                self.assertEquals(1, snapshot.get_value("version") )
            else:
                version = 2
            self.assertEquals(version, snapshot.get_value("version") )

            # check the file object data
            file_objects = snapshot.get_all_file_objects()
            self.assertEquals(1, len(file_objects))
            file_object = file_objects[0]
            repo_filename = file_object.get_value("file_name")

            if server:
                expected = "filename_process_%s_v%0.3d.jpg" % (server, version)
            else:
                expected = "filename_process_v%0.3d.jpg" % (version)
            self.assertEquals(expected, repo_filename)

            relative_dir = file_object.get_value("relative_dir")
            if subdir:
                expected = "unittest/person/%s/process/.versions/%s" % (person_code, subdir)
            else:
                expected = "unittest/person/%s/process/.versions" % person_code
            self.assertEquals(expected, relative_dir)

            asset_dir = Config.get_value("checkin", "asset_base_dir", sub_key="default")
            path = "%s/%s/%s" % (asset_dir, relative_dir, repo_filename)


            # make sure the path from the snapshot is correct
            snapshot_path = snapshot.get_path_by_type("main")
            self.assertEquals(path, snapshot_path)


            exists = os.path.exists(path)
            self.assertEquals(True, exists)


            # check that a versionless has been created
            versionless = Snapshot.get_versionless(self.person.get_search_type(), self.person.get_id(), context, mode='latest', create=False)

            self.assertNotEquals( None, versionless)

            self.assertEquals(-1, versionless.get_value("version") )

            versionless_path = versionless.get_path_by_type("main", "lib")
            versionless_dir = os.path.dirname(versionless_path)

            # test that it is a link
            lexists = os.path.lexists(versionless_path)
            self.assertEquals(True, lexists)

            # check the real path links to the versioned path
            real_path = os.path.realpath(versionless_path)
            self.assertEquals(real_path, path)

            # check that it actually points to a valid path
            exists = os.path.exists(versionless_path)
            self.assertEquals(True, exists)