Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/制造功能优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from ftplib import FTP, error_perm
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -132,7 +133,14 @@ class FtpController:
|
||||
|
||||
|
||||
|
||||
def transfer_nc_files(source_ftp_info, target_ftp_info, source_dir, target_dir, end_with='.nc', keep_dir=False):
|
||||
def transfer_nc_files(
|
||||
source_ftp_info,
|
||||
target_ftp_info,
|
||||
source_dir,
|
||||
target_dir,
|
||||
end_with=None,
|
||||
match_str=None,
|
||||
keep_dir=False):
|
||||
"""
|
||||
从源FTP服务器下载所有{end_with}结尾的文件并上传到目标FTP服务器,保持目录结构
|
||||
|
||||
@@ -143,23 +151,28 @@ def transfer_nc_files(source_ftp_info, target_ftp_info, source_dir, target_dir,
|
||||
target_dir: str, 目标FTP上的目标目录
|
||||
keep_dir: bool, 是否保持目录结构,默认False
|
||||
"""
|
||||
trans_status = [False]
|
||||
try:
|
||||
# 连接源FTP
|
||||
source_ftp = FtpController(
|
||||
source_ftp_info['host'],
|
||||
source_ftp_info['port'],
|
||||
source_ftp_info['port'],
|
||||
source_ftp_info['username'],
|
||||
source_ftp_info['password']
|
||||
)
|
||||
if not source_ftp.ftp:
|
||||
raise Exception("编程文件FTP连接失败")
|
||||
source_ftp.ftp.set_pasv(1)
|
||||
|
||||
# 连接目标FTP
|
||||
target_ftp = FtpController(
|
||||
target_ftp_info['host'],
|
||||
target_ftp_info['port'],
|
||||
target_ftp_info['username'],
|
||||
target_ftp_info['username'],
|
||||
target_ftp_info['password']
|
||||
)
|
||||
if not source_ftp.ftp:
|
||||
raise Exception("机床FTP连接失败")
|
||||
source_ftp.ftp.set_pasv(1)
|
||||
|
||||
# 递归遍历源目录
|
||||
@@ -183,8 +196,14 @@ def transfer_nc_files(source_ftp_info, target_ftp_info, source_dir, target_dir,
|
||||
traverse_dir(f"{current_dir}/{item}", new_relative_path)
|
||||
source_ftp.ftp.cwd('..')
|
||||
except:
|
||||
# 如果是.nc文件则传输
|
||||
if item.lower().endswith(end_with):
|
||||
matched = False
|
||||
# 文件名匹配字符串BT30-(两个字符)-all.nc, 例6667_20250422-BT30-ZM-all.nc
|
||||
if match_str and re.match(match_str, item):
|
||||
matched = True
|
||||
elif end_with and item.lower().endswith(end_with):
|
||||
matched = True
|
||||
|
||||
if matched:
|
||||
# 下载到临时文件
|
||||
temp_path = f"/tmp/{item}"
|
||||
with open(temp_path, 'wb') as f:
|
||||
@@ -198,6 +217,7 @@ def transfer_nc_files(source_ftp_info, target_ftp_info, source_dir, target_dir,
|
||||
with open(temp_path, 'rb') as f:
|
||||
target_ftp.ftp.storbinary(f'STOR {target_path}', f)
|
||||
|
||||
trans_status[0] = True
|
||||
# 删除临时文件
|
||||
os.remove(temp_path)
|
||||
logging.info(f"已传输文件: {item}")
|
||||
@@ -233,17 +253,17 @@ def transfer_nc_files(source_ftp_info, target_ftp_info, source_dir, target_dir,
|
||||
logging.info(f"已清空目标目录 {target_dir}")
|
||||
except Exception as e:
|
||||
logging.error(f"清空目标目录失败: {str(e)}")
|
||||
return False
|
||||
raise Exception(f"清空目标目录失败: {str(e)}")
|
||||
|
||||
# 开始遍历
|
||||
traverse_dir(source_dir)
|
||||
|
||||
logging.info("所有.nc文件传输完成")
|
||||
return True
|
||||
logging.info("所有文件传输完成")
|
||||
return trans_status[0]
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"传输过程出错: {str(e)}")
|
||||
return False
|
||||
raise e
|
||||
|
||||
finally:
|
||||
# 关闭FTP连接
|
||||
|
||||
@@ -1,26 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<record id="view_delivery_record_form_inherit_sf" model="ir.ui.view">
|
||||
<field name="name">delivery.record.form.inherit.sf</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[last()-3]" position="before">
|
||||
<!-- <page string="下发记录" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>-->
|
||||
<page string="下发记录" attrs='{"invisible": ["!", ("individuation_page_list", "ilike", "HDR")]}'>
|
||||
<field name="delivery_records">
|
||||
<tree create="false">
|
||||
<field name="delivery_type"/>
|
||||
<field name="delivery_time"/>
|
||||
<field name="influence_record"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<!-- <record id="seqence_b_purchase_order" model='ir.sequence'> -->
|
||||
<!-- <field name='name'>Purchase Order</field> -->
|
||||
<!-- <field name='code'>sf_machine_connect.delivery.record</field> -->
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<record id="view_machine_info_form_inherit_sf" model="ir.ui.view">
|
||||
<field name="name">machine.info.form.inherit.sf</field>
|
||||
<field name="model">mrp.workorder</field>
|
||||
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
||||
<field name="inherit_id" ref="sf_manufacturing.view_mrp_production_workorder_tray_form_inherit_sf"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//page[last()-3]" position="before">
|
||||
<xpath expr="//page[@name='CMR']" position="after">
|
||||
<page string="机床信息" attrs='{"invisible": ["!", ("individuation_page_list", "ilike", "MTI")]}'>
|
||||
<group string="机床信息">
|
||||
<group>
|
||||
@@ -33,6 +33,15 @@
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page string="下发记录" attrs='{"invisible": ["!", ("individuation_page_list", "ilike", "HDR")]}'>
|
||||
<field name="delivery_records">
|
||||
<tree create="false">
|
||||
<field name="delivery_type"/>
|
||||
<field name="delivery_time"/>
|
||||
<field name="influence_record"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user