当前位置: 首页>>代码示例>>Python>>正文


Python Environment.get_upload_dir方法代码示例

本文整理汇总了Python中pyasm.common.Environment.get_upload_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.get_upload_dir方法的具体用法?Python Environment.get_upload_dir怎么用?Python Environment.get_upload_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyasm.common.Environment的用法示例。


在下文中一共展示了Environment.get_upload_dir方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(my):
        filename = my.kwargs.get("filename")
        ticket = my.kwargs.get("ticket")
        upload_dir = Environment.get_upload_dir(ticket=ticket)
        # can't rely on that
        #ticket = Environment.get_ticket()
        asset_temp_dir = "%s/temp/%s" % (Environment.get_asset_dir(), ticket)

        if not os.path.exists(asset_temp_dir):
            os.makedirs(asset_temp_dir)

        from_path = "%s/%s" % (upload_dir, filename)
        icon_creator = IconCreator(from_path)
        icon_creator.execute()
        icon_path = icon_creator.get_icon_path()

        to_path = "%s/%s" % (asset_temp_dir, filename)
        
        if icon_path:
            shutil.copy(icon_path, to_path)
            my.info = {
                "web_path": "/assets/temp/%s/%s" % (ticket, filename),
                "lib_path": to_path
            }
        else:
            my.info = {}
开发者ID:2gDigitalPost,项目名称:tactic_src,代码行数:28,代码来源:create_project_cmd.py

示例2: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(my):

        from pyasm.common import ZipUtil
        ziputil = ZipUtil()

        paths = my.kwargs.get("paths")

        upload_dir = Environment.get_upload_dir()
        template_dir = Environment.get_template_dir()

        for path in paths:
            path = path.replace("\\", "/")
            basename = os.path.basename(path)
            upload_path = "%s/%s" % (upload_dir, basename)

            if not upload_path.endswith(".zip"):
                continue

            print "upload: ", upload_path
            if not os.path.exists(upload_path):
                continue


            print "template_dir: ", template_dir
            shutil.move(upload_path, template_dir)
            to_path = "%s/%s" % (template_dir, basename)

            # unzip the file
            ziputil.extract(to_path)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:31,代码来源:project_template_wdg.py

示例3: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(self):
        web = self.get_web()
        keys = web.get_form_keys()
        file_name = self.kwargs.get("file_name")

        # process and get the uploaded files
        dir = Environment.get_upload_dir()
        license_file = "%s/%s" % (dir, file_name)
        if not os.path.exists(license_file):
            raise TacticException("Error retrieving the license file in [%s]"%license_file)

        std_name = 'tactic-license.xml'

        head, file_name = os.path.split(license_file)
        # no restrictions for license file
        #if file_name != std_name:
        #    raise TacticException("License file name should be named tactic-license.xml. The file given is [%s]" %file_name)

        license_dir = Environment.get_license_dir()
        current_license = "%s/%s" %(license_dir, std_name)
        if os.path.exists(current_license):
            FileUndo.remove(current_license)
        FileUndo.move(license_file, current_license)

        self.add_description('Renewed license file')
        security = Environment.get_security()
        security.reread_license()
开发者ID:mincau,项目名称:TACTIC,代码行数:29,代码来源:license_manager_wdg.py

示例4: handle_path

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def handle_path(my, src_path):

        src_path = src_path.replace("\\", "/")

        # upload folder
        basename = os.path.basename(src_path)

        if my.mode =='copy':
            target_path = src_path
            target_dir = os.path.dirname(target_path)
        else:
            target_dir = Environment.get_upload_dir()
            target_path = "%s/%s" % (target_dir, basename)
    

        base_dir = Environment.get_template_dir()
        template_dir = "%s/%s" % (base_dir, my.project_code)
        

        if os.path.exists(template_dir):
            shutil.rmtree(template_dir)
            #raise TacticException("Template is already installed at [%s]" %template_dir)

        # unzip the file
        from pyasm.common import ZipUtil
        # this is fixed for windows if zipping doesn't use compression
        paths = ZipUtil.extract(target_path)

        # veryify that the paths extracted are the expected ones
        rootname, ext = os.path.splitext(basename)

        # check if it unzips at the templates folder directly
        unzip_at_template_dir = False
        # move the plugin zip file to the appropriate folder
        if my.mode == 'copy':
            # if they manually drop the zip file already here, skip
            if target_dir != base_dir:
                shutil.copy(target_path, base_dir)
            else:
                unzip_at_template_dir = True
        else:
            shutil.move(target_path, base_dir)


        # move unzipped files into the plugin area
        # remove any version info, only allow 1 particular version installed for now
        import re
        rootname = re.sub('(.*)(-)(\d.*)', r'\1', rootname)
        unzip_path = "%s/%s" % (target_dir, rootname)
       
        
        dest_dir = '%s/%s'%(base_dir, rootname)
        
        if not unzip_at_template_dir and os.path.exists(dest_dir):
            shutil.rmtree(dest_dir)

            shutil.move(unzip_path, dest_dir)
开发者ID:0-T-0,项目名称:TACTIC,代码行数:59,代码来源:project_template_cmd.py

示例5: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(self):

        import os
        path = self.kwargs.get("path")
        path = path.replace("\\", "/")
        basename = os.path.basename(path)

        upload_dir = Environment.get_upload_dir()

        path = "%s/%s" % (upload_dir, basename)

        paths = ZipUtil.extract(path)


        # TODO: why do we need to read the manifest here?
        # ... should be automatic
        manifest_path = "%s/transaction_log/manifest.xml" % upload_dir
        if not os.path.exists(manifest_path):
            raise TacticException("Cannot find manifest file [%s]" % manifest_path)
        f = codecs.open(manifest_path, 'r', 'utf-8')
        manifest_xml = f.read()
        f.close()
        creator = PluginInstaller(base_dir=upload_dir, manifest=manifest_xml)
        creator.execute()


        # run the transactions
        logs = creator.get_jobs()
        for log in logs:
            transaction_xml = log.get_value("transaction")
            cmd = RunTransactionCmd(transaction_xml=transaction_xml)
            cmd.execute()

            # This is needed here, because normaly, RunTransactionCmd
            # is run by a sync, so it blocks further syncs.  When
            # a transaction session is installed, we need to propogate
            # this to the other machines
            cmd = TransactionQueueAppendCmd()
            input = {
                'search_type': 'sthpw/transaction_log',
                'sobject': log
            }
            cmd.input = input
            cmd.execute()
开发者ID:mincau,项目名称:TACTIC,代码行数:46,代码来源:run_transaction_cmd.py

示例6: __init__

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def __init__(my, **kwargs):
        super(PluginBase,my).__init__(**kwargs)

        # plugin sobject (Not really used anymore?)
        my.search_key = my.kwargs.get("search_key")

        zip_path = my.kwargs.get("zip_path")
        upload_file_name = my.kwargs.get("upload_file_name")

        my.base_dir = my.kwargs.get("base_dir")

        my.plugin_dir = my.kwargs.get("plugin_dir")
        my.manifest = my.kwargs.get("manifest")
        my.code = my.kwargs.get("code")
        my.version = my.kwargs.get("version")

        relative_dir = my.kwargs.get("relative_dir")

        my.verbose = my.kwargs.get("verbose") not in [False, 'false']
        # at the end of this, the following variables are needed in order to
        # define the plugin
        #
        #   version: the version of the plugin
        #   plugin_dir: the directory where the plugin definition is located
        #   manifest: the description of what is in the plugin

        if zip_path:

            # assume the zip path is the same as the basename
            basename = os.path.basename(zip_path)
            basename, ext = os.path.splitext(basename)
            assert ext == '.zip'

            tmp_dir = Environment.get_tmp_dir()

            unzip_dir = "%s/%s" % (tmp_dir, basename)
            if os.path.exists(unzip_dir):
               shutil.rmtree(unzip_dir)


            # unzip the file in to the tmp_dir or plugin_dir (for install)
            zip_util = ZipUtil()
            zip_util.extract(zip_path, base_dir=tmp_dir)


            # assume zip path
            my.plugin_dir, ext = os.path.splitext(zip_path)

            # mv from temp
            if my.plugin_dir != unzip_dir:
                if os.path.exists(my.plugin_dir):
                    shutil.rmtree(my.plugin_dir)
                shutil.move(unzip_dir, my.plugin_dir)

            manifest_path = "%s/manifest.xml" % my.plugin_dir
            f = open(manifest_path, 'r')
            my.manifest = f.read()
            f.close()


        elif upload_file_name:
            # The path is moved to the plugin dir, if this process is taking
            # "local" file (such as one uploaded)
            upload_dir = Environment.get_upload_dir()
            upload_path = "%s/%s" % (upload_dir, upload_file_name)
            plugin_base_dir = Environment.get_plugin_dir()
            dist_dir = Environment.get_dist_dir()
            if not os.path.exists(dist_dir):
                os.makedirs(dist_dir)

            basename = os.path.basename(upload_path)
            #if os.path.exists("%s/%s" % (plugin_base_dir, basename)):
            #    os.unlink("%s/%s" % (plugin_base_dir, basename) )
            #shutil.move(upload_path, plugin_base_dir)


            # copy to dist folder
            if os.path.exists("%s/%s" % (dist_dir, basename)):
                os.unlink("%s/%s" % (dist_dir, basename) )
            shutil.move(upload_path, dist_dir)

            zip_path = "%s/%s" % (dist_dir, upload_file_name)

            zip_util = ZipUtil()
            zip_util.extract(zip_path, base_dir=plugin_base_dir)

            my.plugin_dir = "%s/%s" % (plugin_base_dir, basename)
            my.plugin_dir = my.plugin_dir[:-4]
            manifest_path = "%s/manifest.xml" % (my.plugin_dir)

            if os.path.exists(manifest_path):
                f = open(manifest_path, 'r')
                my.manifest = f.read()
                f.close()
            else:
                # when uploading, this will likely not be needed
                my.manifest = "<manifest/>"
                return


#.........这里部分代码省略.........
开发者ID:talha81,项目名称:TACTIC-DEV,代码行数:103,代码来源:plugin.py

示例7: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(my):


        filenames = my.kwargs.get("filenames")

        upload_dir = Environment.get_upload_dir()
        base_dir = upload_dir


        search_type = my.kwargs.get("search_type")
        key = my.kwargs.get("key")
        relative_dir = my.kwargs.get("relative_dir")
        if not relative_dir:
            project_code = Project.get_project_code()
            search_type_obj = SearchType.get(search_type)
            table = search_type_obj.get_table()
            relative_dir = "%s/%s" % (project_code, table)



        server = TacticServerStub.get()

        parent_key = my.kwargs.get("parent_key")
        category = my.kwargs.get("category")
        keywords = my.kwargs.get("keywords")
        extra_data = my.kwargs.get("extra_data")
        if extra_data:
            extra_data = jsonloads(extra_data)
        else:
            extra_data = {}


        # TODO: use this to generate a category
        category_script_path = my.kwargs.get("category_script_path")
        """
        ie:
            from pyasm.checkin import ExifMetadataParser
            parser = ExifMetadataParser(path=file_path)
            tags = parser.get_metadata()

            date = tags.get("EXIF DateTimeOriginal")
            return date.split(" ")[0]
        """
 
    

    
        if not SearchType.column_exists(search_type, "name"):
            raise TacticException('The Ingestion puts the file name into the name column which is the minimal requirement. Please first create a "name" column for this sType.')

        for count, filename in enumerate(filenames):

            # first see if this sobjects still exists
            search = Search(search_type)
            search.add_filter("name", filename)
            if relative_dir and search.column_exists("relative_dir"):
                search.add_filter("relative_dir", relative_dir)
            sobject = search.get_sobject()

            # else create a new one
            if not sobject:
                sobject = SearchType.create(search_type)
                sobject.set_value("name", filename)
                if relative_dir and sobject.column_exists("relative_dir"):
                    sobject.set_value("relative_dir", relative_dir)



            # extract metadata
            file_path = "%s/%s" % (base_dir, File.get_filesystem_name(filename))

            # TEST: convert on upload
            try:
                convert = my.kwargs.get("convert")
                if convert:
                    message_key = "IngestConvert001"
                    cmd = ConvertCbk(**convert)
                    cmd.execute()
            except Exception, e:
                print "WARNING: ", e


            if not os.path.exists(file_path):
                raise Exception("Path [%s] does not exist" % file_path)

            # get the metadata from this image
            if SearchType.column_exists(search_type, "relative_dir"):
                if category and category not in ['none', None]:
                    from pyasm.checkin import ExifMetadataParser
                    parser = ExifMetadataParser(path=file_path)
                    tags = parser.get_metadata()

                    date = tags.get("EXIF DateTimeOriginal")
                    if not date:
                        date_str = "No-Date"
                    else:
                        date_str = str(date)
                        # this can't be parsed correctly by dateutils
                        parts = date_str.split(" ")
                        date_str = parts[0].replace(":", "-")
#.........这里部分代码省略.........
开发者ID:funic,项目名称:TACTIC,代码行数:103,代码来源:ingest_wdg.py

示例8: main

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]

#.........这里部分代码省略.........
                                    subject_see = subject
                                    subject = subject.replace(' ','..')
                                    message = '%s has uploaded a new PO File.' % int_data['from_name'].replace('.',' ')
                                    message = '%s<br/>Uploaded PO File: %s' % (message, file_name)
                                    if parent_type == 'twog/order':
                                        sales_repper = parent.get('sales_rep')
                                        sales_rep_email = server.eval("@GET(sthpw/login['login','%s']['location','internal'].email)" % sales_repper)
                                        if sales_rep_email not in [None,'',[]]:
                                            sales_rep_email = sales_rep_email[0]
                                            if int_data['ccs'] not in [None,'']:
                                                int_data['ccs'] = '%s;%s' % (int_data['ccs'], sales_rep_email)
                                            else:
                                                int_data['ccs'] = '%s' % sales_rep_email
                                    int_data['ccs'] = int_data['ccs'].replace(';%s' % sched_email, '').replace('%s;' % sched_email, '')
                                    template = open(internal_template_file, 'r')
                                    filled = ''
                                    for line in template:
                                        line = line.replace('[ORDER_CODE]', int_data['order_code'])
                                        line = line.replace('[PO_NUMBER]', int_data['po_number'])
                                        line = line.replace('[CLIENT_EMAIL]', int_data['client_email'])
                                        line = line.replace('[EMAIL_CC_LIST]', int_data['ccs'])
                                        line = line.replace('[SCHEDULER_EMAIL]', int_data['scheduler_email'])
                                        line = line.replace('[SUBJECT]', subject_see)
                                        line = line.replace('[MESSAGE]', message)
                                        line = line.replace('[CLIENT]', int_data['client_name'])
                                        line = line.replace('[CLIENT_LOGIN]', int_data['client_login'])
                                        line = line.replace('[ORDER_NAME]', int_data.get('order_hyperlink', int_data['order_name']))
                                        line = line.replace('[START_DATE]', fix_date(int_data['start_date']))
                                        line = line.replace('[DUE_DATE]', fix_date(int_data['due_date']))
                                        line = line.replace('[TITLE_ROW]', '')
                                        line = line.replace('[PROJ_ROW]', '')
                                        filled = '%s%s' % (filled, line)
                                    transaction_ticket = server.get_transaction_ticket()
                                    upload_dir = Environment.get_upload_dir(transaction_ticket)
                                    filled = '%s\nMATTACHMENT:%s/%s' % (filled, upload_dir, file_name)
                                    template.close()
                                    filled_in_email = '/var/www/html/formatted_emails/int_snap_inserted_%s.html' % code
                                    filler = open(filled_in_email, 'w')
                                    filler.write(filled)
                                    filler.close()
                                    the_command = "php /opt/spt/custom/formatted_emailer/trusty_emailer.php '''%s''' '''%s''' '''%s''' '''%s''' '''%s''' '''%s'''" % (filled_in_email, int_data['to_email'], int_data['from_email'], int_data['from_name'], subject, int_data['ccs'].replace(';','#Xs*'))
                                    os.system(the_command)
                                    #If the location of the user is external, and we allow this client to receive emails, then send them an email as well
                                    if int_data['location'] == 'external' and allow_client_emails:
                                        ext_data = ed.get_external_data()
                                        template = open(external_template_file, 'r')
                                        filled = ''
                                        for line in template:
                                            line = line.replace('[ORDER_CODE]', ext_data['order_code'])
                                            line = line.replace('[PO_NUMBER]', ext_data['po_number'])
                                            line = line.replace('[CLIENT_EMAIL]', ext_data['client_email'])
                                            line = line.replace('[EMAIL_CC_LIST]', ext_data['ccs'])
                                            line = line.replace('[SCHEDULER_EMAIL]', ext_data['scheduler_email'])
                                            line = line.replace('[SUBJECT]', subject_see)
                                            line = line.replace('[MESSAGE]', message)
                                            line = line.replace('[CLIENT]', ext_data['client_name'])
                                            line = line.replace('[CLIENT_LOGIN]', ext_data['client_login'])
                                            line = line.replace('[ORDER_NAME]', ext_data['order_name'])
                                            line = line.replace('[START_DATE]', fix_date(ext_data['start_date']))
                                            line = line.replace('[DUE_DATE]', fix_date(ext_data['due_date']))
                                            filled = '%s%s' % (filled, line)
                                        filled = '%s\nMATTACHMENT:%s/%s' % (filled, upload_dir, file_name)
                                        template.close()
                                        filled_in_email = '/var/www/html/formatted_emails/ext_snap_inserted_%s.html' % code
                                        filler = open(filled_in_email, 'w')
                                        filler.write(filled)
开发者ID:2gDigitalPost,项目名称:custom,代码行数:70,代码来源:file_inserted.py

示例9: execute

# 需要导入模块: from pyasm.common import Environment [as 别名]
# 或者: from pyasm.common.Environment import get_upload_dir [as 别名]
    def execute(my):

        filenames = my.kwargs.get("filenames")

        upload_dir = Environment.get_upload_dir()
        base_dir = upload_dir

        update_mode = my.kwargs.get("update_mode")
        search_type = my.kwargs.get("search_type")
        key = my.kwargs.get("key")
        relative_dir = my.kwargs.get("relative_dir")
        if not relative_dir:
            project_code = Project.get_project_code()
            search_type_obj = SearchType.get(search_type)
            table = search_type_obj.get_table()
            relative_dir = "%s/%s" % (project_code, table)

        server = TacticServerStub.get()

        parent_key = my.kwargs.get("parent_key")
        category = my.kwargs.get("category")
        keywords = my.kwargs.get("keywords")
        update_data = my.kwargs.get("update_data")
        extra_data = my.kwargs.get("extra_data")
        if extra_data:
            extra_data = jsonloads(extra_data)
        else:
            extra_data = {}

        # TODO: use this to generate a category
        category_script_path = my.kwargs.get("category_script_path")
        """
        ie:
            from pyasm.checkin import ExifMetadataParser
            parser = ExifMetadataParser(path=file_path)
            tags = parser.get_metadata()

            date = tags.get("EXIF DateTimeOriginal")
            return date.split(" ")[0]
        """

        if not SearchType.column_exists(search_type, "name"):
            raise TacticException('The Ingestion puts the file name into the name column which is the minimal requirement. Please first create a "name" column for this sType.')

        input_prefix = update_data.get('input_prefix')
        non_seq_filenames = []

        # For sequence mode, take all filenames, and regenerate the filenames based on the function "find_sequences"
        if update_mode == "sequence":
            
            non_seq_filenames_dict, seq_digit_length = my.find_sequences(filenames)
            # non_seq_filenames is a list of filenames that are stored in the None key,
            # which are the filenames that are not part of a sequence, or does not contain
            # a sequence pattern.
            non_seq_filenames = non_seq_filenames_dict[None]
            
            # delete the None key from list so filenames can be used in the latter for loop
            del non_seq_filenames_dict[None]
            filenames = non_seq_filenames_dict.keys()
            if filenames == []:
                raise TacticException('No sequences are found in files. Please follow the pattern of [filename] + [digits] + [file extension (optional)]. Examples: [abc_1001.png, abc_1002.png] [abc.1001.mp3, abc.1002.mp3] [abc_100_1001.png, abc_100_1002.png]')

        for count, filename in enumerate(filenames):
        # Check if files should be updated. 
        # If so, attempt to find one to update.
        # If more than one is found, do not update.
            if update_mode in ["true", "True"]:
                # first see if this sobjects still exists
                search = Search(search_type)
                search.add_filter("name", filename)
                if relative_dir and search.column_exists("relative_dir"):
                    search.add_filter("relative_dir", relative_dir)
                sobjects = search.get_sobjects()
                if len(sobjects) > 1:
                    sobject = None
                elif len(sobjects) == 1:
                    sobject = sobjects[0]
                else:
                    sobject = None

            elif update_mode == "sequence":
                if not FileGroup.is_sequence(filename):
                    raise TacticException('Please modify sequence naming to have at least three digits.')
                search = Search(search_type)
                search.add_filter("name", filename)

                if relative_dir and search.column_exists("relative_dir"):
                    search.add_filter("relative_dir", relative_dir)
                sobjects = search.get_sobjects()
                if sobjects:
                    sobject = sobjects[0]
                else:
                    sobject = None

            else:
                sobject = None 

            # Create a new file
            if not sobject:
                sobject = SearchType.create(search_type)
#.........这里部分代码省略.........
开发者ID:asmboom,项目名称:TACTIC,代码行数:103,代码来源:ingest_wdg.py


注:本文中的pyasm.common.Environment.get_upload_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。